Exemplo n.º 1
0
        static void CreateAndAddStateScript(MenuCommand command)
        {
            AnimatorState state      = command.context as AnimatorState;
            string        scriptPath = Path.Combine(Path.GetDirectoryName(AssetDatabase.GetAssetPath(state)), state.name + "State.cs");

            File.WriteAllText(Path.GetFullPath(scriptPath)
                              , Template.TransformToText <StateMachineState_cs>(new Dictionary <string, object>
            {
                { "namespacename", UnityEditorExSettings.instance.GetNamespaceName(scriptPath) },
                { "statename", state.name + "State" },
                { "statemachinetype", "StateMachineType" },
                { "controllertype", "ControllerType" },
                { "partial", true }
            }));
            AssetDatabase.ImportAsset(scriptPath);
            AssetDatabase.Refresh();

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

            script.SetScriptTypeWasJustCreatedFromComponentMenu();

            int behaviourId = AnimatorController.CreateStateMachineBehaviour(script);

            typeof(AnimatorState).GetMethod("AddBehaviour", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(state, new object[] { behaviourId });
        }
        private void CreateScript(string scriptPath)
        {
            File.WriteAllText(Path.GetFullPath(scriptPath)
                              , Template.TransformToText <DerivedClass_cs>(new Dictionary <string, object> {
                { "namespacename", UnityEditorExSettings.instance.GetNamespaceName(scriptPath) },
                { "classname", m_ScriptName },
                { "baseclassname", "MonoBehaviour" },
            }));

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

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

            script.SetScriptTypeWasJustCreatedFromComponentMenu();

            InternalEditorUtilityEx.AddScriptComponentUncheckedUndoable(target, script);
        }
            public override void Create()
            {
                if (!this.IsShow())
                {
                    this.Show();
                    AddStateMachineBehaviourComponentWindow.className = AddStateMachineBehaviourComponentWindow.searchName;
                    return;
                }
                if (!this.CanCreate())
                {
                    return;
                }
                this.CreateScript();
                MonoScript monoScript = AssetDatabase.LoadAssetAtPath(this.TargetPath(), typeof(MonoScript)) as MonoScript;

                monoScript.SetScriptTypeWasJustCreatedFromComponentMenu();
                AddStateMachineBehaviourComponentWindow.s_AddComponentWindow.AddBehaviour(monoScript);
                AddStateMachineBehaviourComponentWindow.s_AddComponentWindow.Close();
            }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static bool CreateAnimatorScript <TemplateType>(Animator animator, AnimatorController controller, string typeName, string postfix, out MonoScript script)
            where TemplateType : new()
        {
            bool   bNewScript = false;
            string scriptPath = MonoScriptEx.GetComponentScriptPath(animator.gameObject.GetComponent(typeName + postfix) as MonoBehaviour);

            if (scriptPath == null)
            {
                bNewScript = true;
                scriptPath = Path.Combine(Path.GetDirectoryName(AssetDatabase.GetAssetPath(controller)), typeName + postfix + ".cs");
            }

            AnimatorControllerExt.CreateAnimatorControllerScript <TemplateType>(controller, typeName, postfix, scriptPath, bNewScript);
            script = AssetDatabase.LoadAssetAtPath <MonoScript>(scriptPath);

            if (bNewScript)
            {
                script.SetScriptTypeWasJustCreatedFromComponentMenu();
            }

            return(bNewScript);
        }