private static void AddToSceneInEditor()
        {
            StatsMonitorWrapper statsMonitorWrapper = FindObjectOfType <StatsMonitorWrapper>();

            if (statsMonitorWrapper == null)
            {
                GameObject wrapper = GameObject.Find(WRAPPER_NAME);
                if (wrapper == null)
                {
                    wrapper = new GameObject(WRAPPER_NAME);
                    UnityEditor.Undo.RegisterCreatedObjectUndo(wrapper, "Create " + WRAPPER_NAME);
                    Util.Utils.ResetTransform(wrapper);
                    Util.Utils.AddToUILayer(wrapper);
                    wrapper.AddComponent <StatsMonitorWrapper>();

                    GameObject widget = new GameObject(StatsMonitor.NAME);
                    widget.transform.parent = wrapper.transform;
                    widget.AddComponent <RectTransform>();
                    widget.AddComponent <StatsMonitor>();
                    Util.Utils.AddToUILayer(widget);
                    widget.SetActive(false);
                    //UnityEditor.Selection.activeObject = widget;
                }
                else
                {
                    Debug.LogWarning("Another object named " + WRAPPER_NAME
                                     + " already exists in the scene! Rename or delete it"
                                     + " before trying to add " + WRAPPER_NAME + ".");
                }
            }
            else
            {
                Debug.LogWarning(WRAPPER_NAME + " already exists in the scene!");
            }
        }
Esempio n. 2
0
        // ----------------------------------------------------------------------------
        // Unity Editor Callbacks
        // ----------------------------------------------------------------------------

        public void OnEnable()
        {
            _self = (target as StatsMonitorWrapper);
        }