Exemplo n.º 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);
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 3
0
 private void ToggleLoadPrefab()
 {
     if (instanceIDProp.intValue == 0 || EditorUtility.InstanceIDToObject(instanceIDProp.intValue) == null)
     {
         ActionEditorUtility.LoadPrefab(prefabProp, instanceIDProp);
     }
     else
     {
         ActionEditorUtility.SavePrefab(instanceIDProp);
     }
 }
        internal static void SavePrefab(SerializedProperty instanceIDProp)
        {
            var gitem = EditorUtility.InstanceIDToObject(instanceIDProp.intValue);

            if (gitem != null)
            {
                ActionEditorUtility.ApplyPrefab(gitem as GameObject);
                GameObject.DestroyImmediate(gitem);
            }
            instanceIDProp.intValue = 0;
        }
        internal static void SavePrefab(ref int instanceID)
        {
            var gitem = EditorUtility.InstanceIDToObject(instanceID);

            if (gitem != null)
            {
                ActionEditorUtility.ApplyPrefab(gitem as GameObject);
                GameObject.DestroyImmediate(gitem);
            }
            instanceID = 0;
        }
        internal static void SavePrefab(SerializedProperty instanceIDProp, SerializedProperty rematrixProp, SerializedProperty matrixProp)
        {
            var gitem = EditorUtility.InstanceIDToObject(instanceIDProp.intValue);

            if (gitem != null)
            {
                if (rematrixProp.boolValue)
                {
                    ActionEditorUtility.SaveMatrixInfo(matrixProp, (gitem as GameObject).transform);
                }
                ActionEditorUtility.ApplyPrefab(gitem as GameObject);
                GameObject.DestroyImmediate(gitem);
            }
            instanceIDProp.intValue = 0;
        }
        private void MarchList()
        {
            if (string.IsNullOrEmpty(query) && selected == 0)
            {
                return;
            }

            prefabListWorp.ClearArray();

            for (int i = 0; i < prefabListProp.arraySize; i++)
            {
                var prop       = prefabListProp.GetArrayElementAtIndex(i);
                var prefabProp = prop.FindPropertyRelative("prefab");

                if (prefabProp.objectReferenceValue == null || !prefabProp.objectReferenceValue.name.ToLower().Contains(query.ToLower()))
                {
                    continue;
                }

                var containCommandProp = prop.FindPropertyRelative("containsCommand");
                var containsPickupProp = prop.FindPropertyRelative("containsPickup");

                if (selected == 1)
                {
                    if (!containCommandProp.boolValue)
                    {
                        continue;
                    }
                }
                else if (selected == 2)
                {
                    if (!containsPickupProp.boolValue)
                    {
                        continue;
                    }
                }
                else if (selected == 3)
                {
                    if (containCommandProp.boolValue || containsPickupProp.boolValue)
                    {
                        continue;
                    }
                }

                prefabListWorp.InsertArrayElementAtIndex(0);
                ActionEditorUtility.CopyPropertyValue(prefabListWorp.GetArrayElementAtIndex(0), prefabListProp.GetArrayElementAtIndex(i));
            }
        }
Exemplo n.º 8
0
 private void CloseAllCreated(SerializedProperty arrayProp)
 {
     for (int i = 0; i < arrayProp.arraySize; i++)
     {
         var itemProp       = arrayProp.GetArrayElementAtIndex(i);
         var instanceIDPorp = itemProp.FindPropertyRelative("instanceID");
         var obj            = EditorUtility.InstanceIDToObject(instanceIDPorp.intValue);
         if (obj != null)
         {
             var matrixProp   = itemProp.FindPropertyRelative("matrix");
             var rematrixProp = itemProp.FindPropertyRelative("rematrix");
             ActionEditorUtility.SavePrefab(instanceIDPorp, rematrixProp, matrixProp);
             DestroyImmediate(obj);
         }
         itemProp.isExpanded = false;
     }
 }
Exemplo n.º 9
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);
                    }
                }
            }
        }
        private void ApplyWorpPrefabList()
        {
            List <SerializedProperty> needAdd = new List <SerializedProperty>();

            if (prefabListWorp.arraySize > 0)
            {
                for (int i = 0; i < prefabListWorp.arraySize; i++)
                {
                    var  newProp         = prefabListWorp.GetArrayElementAtIndex(i);
                    var  newprefabProp   = newProp.FindPropertyRelative("prefab");
                    var  newrematrixProp = newProp.FindPropertyRelative("rematrix");
                    bool contain         = false;
                    for (int j = 0; j < prefabListProp.arraySize; j++)
                    {
                        var prop         = prefabListProp.GetArrayElementAtIndex(j);
                        var prefabProp   = prop.FindPropertyRelative("prefab");
                        var rematrixProp = prop.FindPropertyRelative("rematrix");
                        if (prefabProp.objectReferenceValue == newprefabProp.objectReferenceValue)
                        {
                            if (newrematrixProp.boolValue == rematrixProp.boolValue && rematrixProp.boolValue == false)
                            {
                                ActionEditorUtility.CopyPropertyValue(prop, newProp);
                            }
                            contain = true;
                        }
                    }
                    if (!contain)
                    {
                        needAdd.Add(newProp);
                    }
                }
            }

            for (int i = 0; i < needAdd.Count; i++)
            {
                prefabListProp.InsertArrayElementAtIndex(0);
                var newProp = needAdd[i];
                var prop    = prefabListProp.GetArrayElementAtIndex(0);
                ActionEditorUtility.CopyPropertyValue(prop, newProp);
            }
        }
Exemplo n.º 11
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;
                ToggleLoadPrefab();
            }
            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))
                {
                    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);
        }