示例#1
0
        private void OnEnable()
        {
            myTarget = (IndexTableManager)target;

            indexPrefab     = serializedObject.FindProperty("indexPrefab");
            indicatorPrefab = serializedObject.FindProperty("indicatorPrefab");
            alignment       = serializedObject.FindProperty("m_alignment");
            indicatorSize   = serializedObject.FindProperty("indicatorSize");

            BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;

            System.Type type = typeof(IndexTableManager);
            ChangeLayoutGroup = type.GetMethod("ChangeLayoutGroup", bindingFlags);
            ReplaceIndexes    = type.GetMethod("ReplaceIndexes", bindingFlags);
            ReplaceIndicator  = type.GetMethod("ReplaceIndicator", bindingFlags);
            ResizeIndicator   = type.GetMethod("ResizeIndicator", bindingFlags);
        }
        private void CreateIndexTable()
        {
            var idxTable = myTarget.gameObject.GetComponentInChildren(typeof(IndexTableManager), true);

            if (idxTable != null)
            {
                indexTable.objectReferenceValue = idxTable.gameObject;
            }

            if (indexTable.objectReferenceValue == null)
            {
                indexTable.objectReferenceValue = new GameObject("Index Table");
                GameObject indexTableGO = indexTable.objectReferenceValue as GameObject;
                indexTableGO.transform.SetParent(myTarget.transform, false);
                indexTableGO.layer = 5;

                RectTransform indexTableRT = indexTableGO.AddComponent <RectTransform> ();
                indexTableRT.anchorMin        = new Vector2(0.5f, 0);
                indexTableRT.anchorMax        = indexTableRT.anchorMin;
                indexTableRT.anchoredPosition = new Vector2(0f, myTarget.viewport.anchoredPosition.y / 2 + 25f);
                indexTableGO.AddComponent <CanvasRenderer> ();

                //serializedObject.ApplyModifiedProperties ();
                indexTableManager.objectReferenceValue = indexTableGO.AddComponent <IndexTableManager> ();
                IndexTableManager idxTableManager = indexTableManager.objectReferenceValue as IndexTableManager;
                idxTableManager.MoveIndicator(0, invertOrder.boolValue);
                Undo.RegisterCreatedObjectUndo(indexTable.objectReferenceValue, "New Index Table Created");
            }
            else if (indexTable.objectReferenceValue.hideFlags == HideFlags.HideInHierarchy)
            {
                GameObject indexTableGO = (GameObject)indexTable.objectReferenceValue;
                Undo.RegisterCompleteObjectUndo(indexTableGO, "Index Table is now active");
                indexTableGO.hideFlags = HideFlags.None;
                indexTableGO.tag       = "Untagged";
                indexTableGO.SetActive(true);
            }
        }