Пример #1
0
        /// <summary>
        /// 初始化助手
        /// </summary>
        public void OnInitialization()
        {
            ProcedureManager manager = Module as ProcedureManager;

            //创建所有已激活的流程对象
            for (int i = 0; i < manager.ActivatedProcedures.Count; i++)
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(manager.ActivatedProcedures[i]);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(ProcedureBase)))
                    {
                        if (!Procedures.ContainsKey(type))
                        {
                            Procedures.Add(type, Activator.CreateInstance(type) as ProcedureBase);
                            ProcedureTypes.Add(type);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:流程 " + manager.ActivatedProcedures[i] + " 必须继承至流程基类:ProcedureBase!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:丢失流程 " + manager.ActivatedProcedures[i] + "!");
                }
            }
            _defaultProcedure = manager.DefaultProcedure;
        }
Пример #2
0
        private void CreateInitialProcedure()
        {
            if (_isCreateInitialProcedure)
            {
                if (_procedureFolder != null && _initialProcedure != "")
                {
                    string path = _procedureFolder.FullPath + "/" + _initialProcedure + ".cs";
                    if (!File.Exists(path))
                    {
                        TextAsset asset = AssetDatabase.LoadAssetAtPath("Assets/HTFramework/Editor/Utility/Template/ProcedureTemplate.txt", typeof(TextAsset)) as TextAsset;
                        if (asset)
                        {
                            string code = asset.text;
                            code = code.Replace("新建流程", "初始流程(运行 " + _mainSceneName + " 场景会首先进入此流程)");
                            code = code.Replace("#SCRIPTNAME#", _initialProcedure);
                            File.AppendAllText(path, code);
                            asset = null;

                            Main             main      = FindObjectOfType <Main>();
                            ProcedureManager procedure = main.GetComponentByChild <ProcedureManager>("Procedure");
                            procedure.ActivatedProcedures.Add(_initialProcedure);
                            procedure.DefaultProcedure = _initialProcedure;
                        }
                    }
                    else
                    {
                        Log.Error("新建初始流程失败,已存在脚本 " + path);
                    }
                }
            }
        }
        private void CreateMainScene()
        {
            if (_mainSceneFolder != null && _mainSceneName != "")
            {
                Scene scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

                Object prefab = AssetDatabase.LoadAssetAtPath <Object>("Assets/HTFramework/HTFramework.prefab");
                if (prefab)
                {
                    GameObject main = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                    main.name = "HTFramework";
                    main.transform.localPosition = Vector3.zero;
                    main.transform.localRotation = Quaternion.identity;
                    main.transform.localScale    = Vector3.one;

                    if (_isCreateInitialProcedure)
                    {
                        if (_procedureFolder != null && _initialProcedure != "")
                        {
                            string path = _procedureFolder.FullPath + "/" + _initialProcedure + ".cs";
                            if (!File.Exists(path))
                            {
                                TextAsset asset = AssetDatabase.LoadAssetAtPath(EditorPrefsTable.ScriptTemplateFolder + "ProcedureTemplate.txt", typeof(TextAsset)) as TextAsset;
                                if (asset)
                                {
                                    string code = asset.text;
                                    code = code.Replace("新建流程", "初始流程(运行 " + _mainSceneName + " 场景会首先进入此流程)");
                                    code = code.Replace("#SCRIPTNAME#", _initialProcedure);
                                    File.AppendAllText(path, code, Encoding.UTF8);
                                    asset = null;

                                    ProcedureManager procedure = main.GetComponentByChild <ProcedureManager>("Procedure");
                                    procedure.ActivatedProcedures.Add(_initialProcedure);
                                    procedure.DefaultProcedure = _initialProcedure;
                                }
                            }
                            else
                            {
                                Log.Error("新建初始流程失败,已存在脚本 " + path);
                            }
                        }
                    }
                }
                else
                {
                    Log.Error("新建框架主环境失败,丢失主预制体:Assets/HTFramework/HTFramework.prefab");
                }

                EditorSceneManager.MarkSceneDirty(scene);
                EditorSceneManager.SaveScene(scene, _mainSceneFolder.Path + "/" + _mainSceneName + ".unity");
                AssetDatabase.Refresh();
            }
        }
Пример #4
0
        private void OnEnable()
        {
            _target = target as ProcedureManager;

            _procedureTypes.Clear();
            string[] typePaths = AssetDatabase.GetAllAssetPaths();
            for (int i = 0; i < typePaths.Length; i++)
            {
                if (typePaths[i].EndsWith(".cs"))
                {
                    string className = typePaths[i].Substring(typePaths[i].LastIndexOf("/") + 1).Replace(".cs", "");
                    if (!_procedureTypes.ContainsKey(className))
                    {
                        _procedureTypes.Add(className, typePaths[i]);
                    }
                }
            }
        }
Пример #5
0
        private void Check()
        {
            for (int i = 0; i < CheckBuildPreconditions.Count; i++)
            {
                if (!CheckBuildPreconditions[i]())
                {
                    _isCanBuild = false;
                    Log.Error("当前无法构建项目:未满足允许项目构建的前置条件!");
                    return;
                }
            }

            Main main = FindObjectOfType <Main>();

            if (main == null)
            {
                _isCanBuild = false;
                Log.Error("当前无法构建项目:请先打开包含框架主体的场景!");
                return;
            }

            ProcedureManager procedure = main.GetComponentByChild <ProcedureManager>("Procedure");

            if (procedure != null && procedure.ActivatedProcedures.Count <= 0)
            {
                _isCanBuild = false;
                Log.Error("当前无法构建项目:请添加至少一个流程!");
                return;
            }

            EntityManager entity = main.GetComponentByChild <EntityManager>("Entity");

            if (entity != null)
            {
                for (int i = 0; i < entity.DefineEntityTargets.Count; i++)
                {
                    if (entity.DefineEntityTargets[i] == null)
                    {
                        _isCanBuild = false;
                        Log.Error("当前无法构建项目:实体管理器丢失了至少一个预定义对象!");
                        return;
                    }
                }
            }

            UIManager ui = main.GetComponentByChild <UIManager>("UI");

            if (ui != null)
            {
                for (int i = 0; i < ui.DefineUIEntitys.Count; i++)
                {
                    if (ui.DefineUIEntitys[i] == null)
                    {
                        _isCanBuild = false;
                        Log.Error("当前无法构建项目:UI管理器丢失了至少一个预定义对象!");
                        return;
                    }
                }
            }

            _isCanBuild = true;
        }
 public override void OnEnable()
 {
     _target = Target as ProcedureManager;
 }