Ejemplo n.º 1
0
        private void OnPlayModeStateChanged(PlayModeStateChange state)
        {
            switch (state)
            {
            case PlayModeStateChange.EnteredPlayMode:
                actionMachineObj = null;
                actionMachine    = null;
                configAsset      = null;
                config           = null;
                break;

            case PlayModeStateChange.EnteredEditMode:
                //还原最后的选择
                GameObject        obj;
                ActionMachineTest amTest;
                if (!string.IsNullOrEmpty(lastEditorTargetPath) &&
                    (obj = GameObject.Find(lastEditorTargetPath)) != null &&
                    (amTest = obj.GetComponent <ActionMachineTest>()) != null)
                {
                    UpdateTarget(obj);
                    UpdateConfig(amTest.config);
                }
                lastEditorTargetPath = string.Empty;
                break;

            case PlayModeStateChange.ExitingEditMode:
                //记录最后的选择
                lastEditorTargetPath = actionMachineObj?.GetScenePath();
                break;
            }
        }
Ejemplo n.º 2
0
        public static StateConfig GetStateConfig(string configName, string stateName)
        {
            StateConfig config;
            Dictionary <string, StateConfig> stateDict;

            if (stateConfigDict.TryGetValue(configName, out stateDict) &&
                stateDict.TryGetValue(stateName, out config))
            {
                return(config);
            }

            if (stateDict == null)
            {
                stateDict = new Dictionary <string, StateConfig>();
                stateConfigDict.Add(configName, stateDict);
            }

            MachineConfig mConfig = GetMachineConfig(configName);

            config = mConfig.states.Find(t => 0 == string.Compare(stateName, t.stateName));
            if (config == null)
            {
                throw new RuntimeException($"状态机配置 {configName} 中的 {stateName} 未找到");
            }

            stateDict.Add(stateName, config);

            return(config);
        }
Ejemplo n.º 3
0
        private void PasteConfig()
        {
            if (null == win.configAsset)
            {
                throw new RuntimeException($"未选择配置资源");
            }

            MachineConfig config = null;

            try
            {
                string data = EditorGUIUtility.systemCopyBuffer;
                config = DataUtility.FromJson <MachineConfig>(data);
                if (null == config)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Debug.LogWarning("剪贴板数据不匹配");
                return;
            }

            win.config = config;
        }
Ejemplo n.º 4
0
        private void CopyToNew(MachineConfig config)
        {
            string dir      = EditorUtilityEx.GetSelectDirectory();
            string filePath = EditorUtilityEx.ValidFilePath(Path.Combine(dir, "MachineConfig.bytes"));
            string data     = DataUtility.ToJson(config);

            File.WriteAllText(filePath, data);
            AssetDatabase.Refresh();

            Debug.Log($"配置已拷贝到 : {filePath}");
        }
Ejemplo n.º 5
0
        private void PlayMode()
        {
            win.setting.showView = EditorGUILayoutEx.DrawObject("显示", win.setting.showView);
            GUILayout.FlexibleSpace();

            string[] configNames = ActionMachineHelper.loadedConfig.Keys.ToArray();
            if (configNames == null || configNames.Length == 0)
            {
                selectConfigName = string.Empty;

                GUILayout.Label("当前没有已加载的配置文件");
                return;
            }

            bool isInit = true;
            int  index  = 0;

            if (!string.IsNullOrEmpty(selectConfigName))
            {
                index = Array.FindIndex(configNames, t => string.Compare(t, selectConfigName) == 0);
                if (index < 0)
                {
                    index = 0;
                }
            }
            else
            {
                isInit = false;
            }

            GUILayout.Label("已加载配置文件");

            EditorGUI.BeginChangeCheck();
            index = EditorGUILayout.Popup(GUIContent.none, index, configNames, GUILayout.Width(200f));
            if (EditorGUI.EndChangeCheck() || !isInit)
            {
                selectConfigName = configNames[index];

                MachineConfig config = ActionMachineHelper.loadedConfig[selectConfigName];
                win.config = config;
            }

            if (GUILayout.Button("覆盖到", GUILayout.Width(80)))
            {
                GUI.FocusControl(null);
                SaveConfigToSelect(win.config);
            }
            if (GUILayout.Button("另存到", GUILayout.Width(100)))
            {
                GUI.FocusControl(null);
                CopyToNew(win.config);
            }
        }
Ejemplo n.º 6
0
        public void UpdateConfig(TextAsset config)
        {
            if (config == null)
            {
                throw new RuntimeException($"未选择配置资源");
            }

            this.configAsset = config;
            this.config      = DataUtility.FromJson <MachineConfig>(config.text);
            if (this.config == null)
            {
                throw new RuntimeException($"配置资源解析失败");
            }
        }
Ejemplo n.º 7
0
        private void Check()
        {
            if (!isActionMachineValid)
            {
                actionMachineObj = null;
                actionMachine    = null;
            }

            if (!isConfigValid)
            {
                configAsset = null;
                config      = null;
            }

            //更新标题
            //this.titleContent = new GUIContent(configAsset != null ? $"编辑 {configAsset.name} " : $"动作编辑器");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取状态机配置文件
        /// </summary>
        /// <param name="configName">状态机配置文件名</param>
        /// <returns>配置</returns>
        public static MachineConfig GetMachineConfig(string configName)
        {
            MachineConfig config = null;

            if (machineConfigDict.TryGetValue(configName, out config))
            {
                return(config);
            }

            config = loader(configName);
            if (config == null)
            {
                throw new RuntimeException($"状态机配置 {configName} 未找到");
            }
            machineConfigDict.Add(configName, config);

            return(config);
        }
Ejemplo n.º 9
0
        private void SaveConfigToSelect(MachineConfig config)
        {
            string filePath = EditorUtilityEx.GetSelectFile(".bytes");

            if (string.IsNullOrEmpty(filePath))
            {
                Debug.LogWarning("选择的文件无效,写入失败");
                return;
            }

            if (!EditorUtility.DisplayDialog("提示", $"是否将当前配置覆盖到选择文件?\n{filePath}", "是", "否"))
            {
                return;
            }

            string data = DataUtility.ToJson(config);

            File.WriteAllText(filePath, data);
            AssetDatabase.Refresh();

            Debug.Log($"配置已覆盖到 : {filePath}");
        }