Example #1
0
        static void SceneRequrementsGame()
        {
            EditorUtils.CreateGameControllerObject(true);
            UnityEngine.UI.Text textui = _createUI();
            if (textui == null)
            {
                Debug.LogError("Cannot create 'Trigger UI' component.");
            }
            UnityEngine.UI.Text uiText = _createItemPicker();
            if (uiText == null)
            {
                Debug.LogError("Cannot create 'Item Picker UI' component.");
            }

            // assign text ui to trigger manager
            GameObject player = GameObject.FindGameObjectWithTag("Player");

            if (player)
            {
                TriggerManagement tm = player.GetComponent <TriggerManagement>();
                tm.m_TriggerUI = textui;

                ItemPicker ip = player.GetComponent <ItemPicker>();
                ip.DisplayUI = uiText;
            }
            Undo.SetCurrentGroupName("Create Scene Requirements ( Game )");
        }
Example #2
0
        void _createItemPicker()
        {
            if (CharacterType != CharacterTypes.ThirdPerson)
            {
                return;
            }

            ItemPicker ip = character.GetComponent <ItemPicker>();

            if (!ip)
            {
                ip = Undo.AddComponent <ItemPicker>(character);
            }

            UnityEngine.UI.Text uiText = null;

            // load canvas from resources
            Canvas canvas = FindObjectOfType <Canvas>();

            if (canvas)
            {
                Transform uiXform = Utils.FindChildTransformByName(canvas.transform, "ItemPickerUI");
                if (uiXform)
                {
                    uiText = uiXform.GetComponent <UnityEngine.UI.Text>();
                }
                else
                {
                    uiText = Resources.Load <UnityEngine.UI.Text>("ItemPickerUI");
                    uiText = Instantiate(uiText);
                    uiText.transform.SetParent(canvas.transform, false);
                    Undo.RegisterCreatedObjectUndo(uiText.gameObject, "Create Text");
                }
            }
            else
            {
                Debug.Log("creating new canvas...");
                Canvas canvasPrefab = Resources.Load <Canvas>("Canvas");
                if (!canvasPrefab)
                {
                    Debug.LogError("Cannot find 'Canvas' prefab!" + " < " + this.ToString() + ">");
                    return;
                }


                canvas = Instantiate(canvasPrefab);

                Undo.RegisterCreatedObjectUndo(canvas.gameObject, "Create Canvas");


                Transform uiXform = Utils.FindChildTransformByName(canvas.transform, "ItemPickerUI");
                if (uiXform)
                {
                    uiText = uiXform.GetComponent <UnityEngine.UI.Text>();
                }
                else
                {
                    uiText = Resources.Load <UnityEngine.UI.Text>("ItemPickerUI");
                    uiText = Instantiate(uiText);
                    uiText.transform.SetParent(canvas.transform, false);
                    Undo.RegisterCreatedObjectUndo(uiText.gameObject, "Create Text");
                }
            }
            canvas.name = "Canvas";
            uiText.name = "ItemPickerUI";

            // load picker indicator image if dont exists
            // first check if exists
            GameObject pImg = GameObject.Find("PickerIndicatorImage");

            if (!pImg)
            {
                UnityEngine.UI.Image pickerImg = Resources.Load <UnityEngine.UI.Image>("PickerIndicatorImage");
                if (pickerImg)
                {
                    pickerImg = Instantiate(pickerImg);
                    pickerImg.transform.SetParent(canvas.transform, false);
                    pickerImg.name = "PickerIndicatorImage";
                    Undo.RegisterCreatedObjectUndo(pickerImg.gameObject, "Create Image");
                }
            }

            Material outline = Resources.Load <Material>("Materials/OutlineStandardSpec");

            if (outline)
            {
                ip.outlineMaterial = outline;
            }

            ip.DisplayUI    = uiText;
            ip.pickDistance = 3.0f;
            ip.layers       = LayerMask.GetMask(/*"Default", */ "DefaultSlope", "Walkable", "Item");
            ip.layers      |= 1 << LayerMask.NameToLayer("Default");
        }