예제 #1
0
        private void DrawPrefabElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            var btnRect   = new Rect(rect.x, rect.y, rect.width - 60, EditorGUIUtility.singleLineHeight);
            var titleRect = new Rect(rect.x + btnRect.width * 0.5f, rect.y, btnRect.width * 0.5f, btnRect.height);

            var obj        = prefabsProp.GetArrayElementAtIndex(index);
            var instenceID = GetInstenceID(obj.objectReferenceValue);
            var objName    = obj.objectReferenceValue == null ? "" : obj.objectReferenceValue.name;

            if (GUI.Button(btnRect, objName, EditorStyles.toolbarDropDown))
            {
                if (obj.objectReferenceValue != null)
                {
                    if (instenceID == 0 || EditorUtility.InstanceIDToObject(instenceID) == null)
                    {
                        ActionEditorUtility.LoadPrefab(obj.objectReferenceValue as GameObject, ref instenceID);
                    }
                    else
                    {
                        ActionEditorUtility.SavePrefab(ref instenceID);
                    }
                }
                SaveInstenceID(obj.objectReferenceValue, instenceID);
            }
            if (instenceID != 0)
            {
                EditorGUI.LabelField(titleRect, instenceID.ToString());
            }

            var objRect = new Rect(rect.x + btnRect.width, rect.y, 60, btnRect.height);

            obj.objectReferenceValue = EditorGUI.ObjectField(objRect, obj.objectReferenceValue, typeof(GameObject), false);
        }
예제 #2
0
        private void GroupLoadPrefabs(SerializedProperty proprety)
        {
            for (int i = 0; i < proprety.arraySize; i++)
            {
                var        itemProp       = proprety.GetArrayElementAtIndex(i);
                GameObject prefab         = null;
                var        prefabProp     = itemProp.FindPropertyRelative("prefab");
                var        instanceIDProp = itemProp.FindPropertyRelative("instanceID");
                if (instanceIDProp.intValue != 0)
                {
                    var gitem = EditorUtility.InstanceIDToObject(instanceIDProp.intValue);
                    if (gitem != null)
                    {
                        continue;
                    }
                }
                prefab = prefabProp.objectReferenceValue as GameObject;

                if (prefab == null)
                {
                    UnityEditor.EditorUtility.DisplayDialog("空对象", "找不到预制体", "确认");
                }
                else
                {
                    var matrixProp          = itemProp.FindPropertyRelative("matrix");
                    var rematrixProp        = itemProp.FindPropertyRelative("rematrix");
                    var containsCommandProp = itemProp.FindPropertyRelative("containsCommand");
                    var containsPickupProp  = itemProp.FindPropertyRelative("containsPickup");
                    ActionEditorUtility.LoadPrefab(prefabProp, containsCommandProp, containsPickupProp, instanceIDProp, rematrixProp, matrixProp);
                    itemProp.isExpanded = true;
                }
            }
        }
예제 #3
0
 private void ToggleLoadPrefab()
 {
     if (instanceIDProp.intValue == 0 || EditorUtility.InstanceIDToObject(instanceIDProp.intValue) == null)
     {
         ActionEditorUtility.LoadPrefab(prefabProp, instanceIDProp);
     }
     else
     {
         ActionEditorUtility.SavePrefab(instanceIDProp);
     }
 }
예제 #4
0
        private void DrawPrefabsHeader(Rect rect)
        {
            var titleRect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(titleRect, "预制体列表");
            var createAllRect = new Rect(rect.x + rect.width - 3 * btnWidth, rect.y, btnWidth, EditorGUIUtility.singleLineHeight);

            if (GUI.Button(createAllRect, "clear"))
            {
                var confer = EditorUtility.DisplayDialog("温馨提示", "如需清除所有记录的预制体,请按确认", "确认");
                if (confer)
                {
                    prefabsProp.ClearArray();
                }
            }
            createAllRect.x += btnWidth;
            if (GUI.Button(createAllRect, "open"))
            {
                for (int i = 0; i < prefabsProp.arraySize; i++)
                {
                    var obj = prefabsProp.GetArrayElementAtIndex(i);
                    if (obj.objectReferenceValue != null)
                    {
                        var instenceID = GetInstenceID(obj.objectReferenceValue);
                        ActionEditorUtility.LoadPrefab(obj.objectReferenceValue as GameObject, ref instenceID);
                        SaveInstenceID(obj.objectReferenceValue, instenceID);
                    }
                }
            }
            createAllRect.x += btnWidth;
            if (GUI.Button(createAllRect, "save"))
            {
                for (int i = 0; i < prefabsProp.arraySize; i++)
                {
                    var obj = prefabsProp.GetArrayElementAtIndex(i);
                    if (obj.objectReferenceValue != null)
                    {
                        var instenceID = GetInstenceID(obj.objectReferenceValue);
                        ActionEditorUtility.SavePrefab(ref instenceID);
                        SaveInstenceID(obj.objectReferenceValue, instenceID);
                    }
                }
            }
        }
예제 #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            FindCommonPropertys(property);
            prefabProp = property.FindPropertyRelative("prefab");

            if (prefabProp.objectReferenceValue != null)
            {
                label = new GUIContent(prefabProp.objectReferenceValue.name);
            }
            var rect = new Rect(position.x, position.y, position.width * 0.9f, EditorGUIUtility.singleLineHeight);
            var str  = prefabProp.objectReferenceValue == null ? "" : prefabProp.objectReferenceValue.name;

            GUI.contentColor = Color.cyan;
            if (GUI.Button(rect, str, EditorStyles.toolbarDropDown))
            {
                property.isExpanded = !property.isExpanded;
                if (property.isExpanded)
                {
                    ActionEditorUtility.LoadPrefab(prefabProp, containsCommandProp, containsPickupProp, instanceIDProp, rematrixProp, matrixProp);
                }
                else
                {
                    ActionEditorUtility.SavePrefab(instanceIDProp, rematrixProp, matrixProp);
                }
            }
            GUI.contentColor = Color.white;

            InformationShow(rect);

            rect = new Rect(position.max.x - position.width * 0.1f, position.y, 20, EditorGUIUtility.singleLineHeight);

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (rect.Contains(Event.current.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                }
                break;

            case EventType.DragPerform:
                if (rect.Contains(Event.current.mousePosition))
                {
                    Debug.Log(DragAndDrop.objectReferences.Length);
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        var obj = DragAndDrop.objectReferences[0];
                        if (obj is GameObject)
                        {
                            ActionEditorUtility.InsertItem(prefabProp, obj);
                        }
                        DragAndDrop.AcceptDrag();
                    }
                    Event.current.Use();
                }
                break;

            case EventType.DragExited:
                break;
            }

            if (prefabProp.objectReferenceValue != null)
            {
                if (GUI.Button(rect, "", EditorStyles.objectFieldMiniThumb))
                {
                    EditorGUIUtility.PingObject(prefabProp.objectReferenceValue);
                }
            }
            else
            {
                prefabProp.objectReferenceValue = EditorGUI.ObjectField(rect, null, typeof(GameObject), false);
            }

            rect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight);

            if (property.isExpanded)
            {
                DrawOptions(rect);
            }
        }