Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            if (_scriptCreater == null)
            {
                _scriptCreater = this.target as ScriptCreater;
            }
            _scriptCreater = this.target as ScriptCreater;

            this.Space(10)
            .ETextField("Script Name", ref _scriptCreater.ScriptName)
            .Pan(() => {
                if (!_scriptCreater.ScriptName.IsLegalFieldName())
                {
                    _scriptCreater.ScriptName = _scriptCreater.name.Replace(" ", "").Replace("(", "").Replace(")", "");
                }
            })
            .Label("Description")
            .TextArea(ref _scriptCreater.description, GUILayout.Height(40))
            .Space(10)
            .DrawHorizontal(() => {
                GUILayout.Label(new GUIContent("Create Path:", "Drag Floder To Box"));
                Rect rect = EditorGUILayout.GetControlRect();
                rect.DrawOutLine(2, Color.black);
                EditorGUI.LabelField(rect, _scriptCreater.CreatePath);
                if (!rect.Contains(Event.current.mousePosition))
                {
                    return;
                }
                var info = EditorTools.DragAndDropTool.Drag(Event.current, rect);
                if (info.paths.Length > 0 && info.compelete && info.enterArera && info.paths[0].IsDirectory())
                {
                    _scriptCreater.CreatePath = info.paths[0];
                }
            })
            .Space(10)
            .DrawHorizontal(() => {
                if (GUILayout.Button("Build", GUILayout.Height(25)))
                {
                    if (BuildCheck())
                    {
                        Selection.objects = new Object[] { AssetDatabase.LoadAssetAtPath <Object>(_scriptCreater.CreatePath) };
                        CopyAsset.Copy(_scriptCreater.ScriptName.Append(".cs"), originScriptPath);
                    }
                }
                if (GUILayout.Button("Remove", GUILayout.Height(25)))
                {
                    _scriptCreater.GetComponentsInChildren <ScriptMark>(true).ToList().ForEach((sm) => {
                        DestroyImmediate(sm);
                    });
                    DestroyImmediate(_scriptCreater);
                }
            });
            try
            {
                serializedObject.Update();
            }
            catch (Exception) { }
        }
Esempio n. 2
0
 private void OnEnable()
 {
     originScriptPath = EditorEnv.CorePath.CombinePath(@"ScriptCreater/Editor/FormatScript.txt");
     _scriptCreater   = this.target as ScriptCreater;
 }
Esempio n. 3
0
        private static void SetFields()
        {
            if (!EditorPrefs.GetBool(IsCreateKey, false))
            {
                return;
            }
            if (!EditorPrefs.HasKey(ScriptNameKey) || !EditorPrefs.HasKey(GameobjKey))
            {
                if (EditorPrefs.HasKey(ScriptNameKey))
                {
                    EditorPrefs.DeleteKey(ScriptNameKey);
                }
                if (EditorPrefs.HasKey(GameobjKey))
                {
                    EditorPrefs.DeleteKey(GameobjKey);
                }
                EditorPrefs.SetBool(IsCreateKey, false);
                EditorUtility.ClearProgressBar();
                return;
            }

            Assembly defaultAssembly = AppDomain.CurrentDomain.GetAssemblies()
                                       .First(assembly => assembly.GetName().Name == "Assembly-CSharp");
            Type       type    = defaultAssembly.GetType(ProjectConfig.NameSpace + "." + EditorPrefs.GetString(ScriptNameKey));
            GameObject gameObj = GameObject.Find(EditorPrefs.GetString(GameobjKey));

            if (gameObj == null || type == null || gameObj.GetComponent <ScriptCreater>() == null)
            {
                if (EditorPrefs.HasKey(ScriptNameKey))
                {
                    EditorPrefs.DeleteKey(ScriptNameKey);
                }
                if (EditorPrefs.HasKey(GameobjKey))
                {
                    EditorPrefs.DeleteKey(GameobjKey);
                }
                EditorPrefs.SetBool(IsCreateKey, false);
                EditorUtility.ClearProgressBar();
                return;
            }
            EditorUtility.DisplayProgressBar("Build Script  " + type.Name, "Don't do anything", 0.7f);
            _scriptCreater = gameObj.GetComponent <ScriptCreater>();

            ScriptMark[] scriptMarks = _scriptCreater.scriptMarks;
            Component    component   = gameObj.GetComponent(type);

            if (component == null)
            {
                component = gameObj.AddComponent(type);
            }
            SerializedObject serialiedScript = new SerializedObject(component);

            foreach (var _sm in scriptMarks)
            {
                serialiedScript.FindProperty(_sm.fieldName).objectReferenceValue = _sm.GetComponent(_sm.fieldType);
            }
            serialiedScript.ApplyModifiedPropertiesWithoutUndo();
            //serialiedScript.Update();
            if (_scriptCreater.isCreatePrefab)
            {
                EditorUtil.CreatePrefab(gameObj, _scriptCreater.prefabPath);
            }



            EditorPrefs.SetBool(IsCreateKey, false);
            EditorPrefs.DeleteKey(ScriptNameKey);
            EditorPrefs.DeleteKey(GameobjKey);
            EditorUtility.ClearProgressBar();
        }
Esempio n. 4
0
        private static void SetFields()
        {
            if (!EditorPrefs.GetBool(IsCreateKey, false))
            {
                return;
            }
            if (!EditorPrefs.HasKey(ScriptNameKey) || !EditorPrefs.HasKey(GameobjKey))
            {
                if (EditorPrefs.HasKey(ScriptNameKey))
                {
                    EditorPrefs.DeleteKey(ScriptNameKey);
                }
                if (EditorPrefs.HasKey(GameobjKey))
                {
                    EditorPrefs.DeleteKey(GameobjKey);
                }
                EditorPrefs.SetBool(IsCreateKey, false);
                EditorUtility.ClearProgressBar();
                return;
            }

            Assembly defaultAssembly = AppDomain.CurrentDomain.GetAssemblies()
                                       .First(assembly => assembly.GetName().Name == "Assembly-CSharp");
            Type type = defaultAssembly.GetType(ProjectConfig.NameSpace + "." + EditorPrefs.GetString(ScriptNameKey));

            ScriptCreater sc = GameObject.FindObjectsOfType <ScriptCreater>().ToList().Find((_sc) => { return(_sc.name == EditorPrefs.GetString(GameobjKey)); });

            if (sc == null || type == null)
            {
                if (EditorPrefs.HasKey(ScriptNameKey))
                {
                    EditorPrefs.DeleteKey(ScriptNameKey);
                }
                if (EditorPrefs.HasKey(GameobjKey))
                {
                    EditorPrefs.DeleteKey(GameobjKey);
                }
                EditorPrefs.SetBool(IsCreateKey, false);
                EditorUtility.ClearProgressBar();
                return;
            }
            EditorUtility.DisplayProgressBar("Build Script  " + type.Name, "Don't do anything", 0.7f);

            ScriptMark[] scriptMarks = sc.scriptMarks;
            Component    component   = sc.GetComponent(type);

            if (component == null)
            {
                component = sc.gameObject.AddComponent(type);
            }
            SerializedObject serialiedScript = new SerializedObject(component);

            foreach (var _sm in scriptMarks)
            {
                var _type = _sm.fieldType;
                if (_type.StartsWith("UnityEngine.") && _type.LastIndexOf(".") == "UnityEngine".Length)
                {
                    _type = _type.Replace("UnityEngine.", "");
                }
                serialiedScript.FindProperty(_sm.fieldName).objectReferenceValue = _sm.GetComponent(_type);
            }
            serialiedScript.ApplyModifiedPropertiesWithoutUndo();
            //serialiedScript.Update();


            EditorPrefs.SetBool(IsCreateKey, false);
            EditorPrefs.DeleteKey(ScriptNameKey);
            EditorPrefs.DeleteKey(GameobjKey);
            EditorUtility.ClearProgressBar();
        }