static void CreateAndAddStateMachineScript(MenuCommand command)
        {
            var animator   = command.context as Animator;
            var controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(AssetDatabase.GetAssetPath(animator.runtimeAnimatorController));

            MonoScript script;
            string     stateMachineName = controller.name.Replace("StateMachine", "");

            if (CreateAnimatorScript <BaseStateMachine_cs>(animator, controller, stateMachineName, "StateMachine", out script))
            {
                InternalEditorUtilityEx.AddScriptComponentUncheckedUndoable(animator.gameObject, script);
            }
        }
Exemple #2
0
        public static void AddGameObjectScript(MenuCommand command)
        {
            Transform transfrom  = command.context as Transform;
            string    scriptPath = Path.Combine(ProjectBrowserExt.GetSelectedPath(), transfrom.gameObject.name + ".cs");

            File.WriteAllText(Path.GetFullPath(scriptPath)
                              , Template.TransformToText <DerivedClass_cs>(new Dictionary <string, object>
            {
                { "namespacename", UnityEditorExSettings.instance.GetNamespaceName(scriptPath) },
                { "classname", transfrom.gameObject.name },
                { "baseclassname", "MonoBehaviour" },
            }));

            AssetDatabase.ImportAsset(scriptPath);
            AssetDatabase.Refresh();

            MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(scriptPath);

            script.SetScriptTypeWasJustCreatedFromComponentMenu();
            InternalEditorUtilityEx.AddScriptComponentUncheckedUndoable(transfrom.gameObject, script);
        }