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);
        }
Exemple #2
0
        internal static GameObject LoadPrefab(string guid, SerializedProperty instenceIDProp, SerializedProperty coordinateProp)
        {
            if (instenceIDProp.intValue != 0)
            {
                var gitem = EditorUtility.InstanceIDToObject(instenceIDProp.intValue);
                if (gitem != null)
                {
                    GameObject.DestroyImmediate(gitem);
                }
            }

            if (string.IsNullOrEmpty(guid) || string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(guid)))
            {
                return(null);
            }
            else
            {
                GameObject prefab      = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(guid));
                var        id          = instenceIDProp.intValue;
                var        instenceObj = ActionEditorUtility.LoadPrefab(prefab, ref id);
                instenceIDProp.intValue = id;
                ActionEditorUtility.LoadCoordinatePropInfo(coordinateProp, instenceObj.transform);
                return(instenceObj);
            }
        }
Exemple #3
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;
        }
Exemple #4
0
        internal static void SavePrefab(SerializedProperty instanceIDProp, bool ignoreTranform)
        {
            var gitem = EditorUtility.InstanceIDToObject(instanceIDProp.intValue);

            if (gitem != null)
            {
                if (!ignoreTranform || !Ignore(gitem))
                {
                    ActionEditorUtility.ApplyPrefab(gitem as GameObject);
                }
                GameObject.DestroyImmediate(gitem);
            }
            instanceIDProp.intValue = 0;
        }
Exemple #5
0
        internal static void SavePrefab(SerializedProperty instanceIDProp, SerializedProperty coordinate)
        {
            var gitem = EditorUtility.InstanceIDToObject(instanceIDProp.intValue);

            if (gitem != null)
            {
                var transform = (gitem as GameObject).transform;
                ActionEditorUtility.SaveCoordinatesInfo(coordinate, transform);
                if (!Ignore(gitem))
                {
                    ActionEditorUtility.ApplyPrefab(gitem as GameObject);
                }
                GameObject.DestroyImmediate(gitem);
            }
            instanceIDProp.intValue = 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);
                    }
                }
            }
        }