Text.font = Resources.GetBuiltinResource( "Arial. Var textTransform = textObj.AddComponent() Var textObj = new GameObject( "ButtonLabel") Image.sprite = AssetDatabase.GetBuiltinExtraResource( "UI/Skin/UISprite.psd") Var buttonTransform = buttonObj.AddComponent() īuttonTransform.sizeDelta = new Vector2( 200, 64) īuttonTransform.SetParent(FindObjectOfType().transform, false) Var buttonObj = new GameObject( "Button") create a new button with label, position and click handler public Button CreateButton(Vector3 position, string aLabel, method) if one of our branch button is clicked, we just tell our flow player to continue with the traversal called when a button is clicked, this makes sure t void ButtonClick( int aId) this is very rough code and would in its current form delete everytime all buttons found in the scene // The code would be a lot easier and cleaner with prefabs, but then would be difficult to show in a script only example. Unity uses sprites by default when the engine. modify our position for the next button, so we create a simple vertical list of buttons. Unity Creating Sprites - Sprites are simple 2D objects that have graphical images (called textures) on them. Var menuTxt = branch.Target as IObjectWithMenuText īranch localBranch = branch // necessary when we iterate over it (modified closure) // create the buttonĬreateButton(pos, buttonLabel, () => ButtonClick(localBranch.BranchId)) Var text = branch.Target as IObjectWithText to give the button a nice label, we use the object interfaces and check which one is the most appropriate var dspName = branch.Target as IObjectWithDisplayName build a label depending on the target string buttonLabel = "Unknown" we saw in the first recipe of this chapter, we also need to set Image Type to Sliced. if a branch is not valid, we don't want to create a button for it if (!branch.IsValid) continue UI components that are outside Canvas will not be drawn by Unity. now we create for every branch a button foreach ( var branch in aBranches) ![]() delete all old buttons from previous branches var oldButtons = FindObjectsOfType() Select the image once its in the project window and make sure that it is set to a Texture Type of Texture in your inspector. this will be called when we have new branches and we want to display each branch as a button on the screen public void OnBranchesUpdated(IList aBranches) First import your image into your project by simply dropping it in your project window. Var menuTxt = aObject as IObjectWithMenuText Var dspName = aObject as IObjectWithDisplayName 11 When I add a ui-image to a panel, the 'Source Image' in Unit圓d says none (Sprite). Public void OnFlowPlayerPaused(IFlowObject aObject) Public class BranchingExampleScript : MonoBehaviour, IArticyFlowPlayerCallbacks
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |