/// <summary> /// 创建步骤助手 /// </summary> private StepHelper CreateHelper(StepContent content, StepHelperTask task) { if (!string.IsNullOrEmpty(content.Helper) && content.Helper != "<None>") { Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(content.Helper); if (type != null) { StepHelper helper = Activator.CreateInstance(type) as StepHelper; for (int i = 0; i < content.Parameters.Count; i++) { StepParameter parameter = content.Parameters[i]; if (parameter.Type == StepParameter.ParameterType.GameObject) { if (_targets.ContainsKey(parameter.GameObjectGUID)) { parameter.GameObjectValue = _targets[parameter.GameObjectGUID].gameObject; } } helper.Parameters.Add(parameter); } helper.Content = content; helper.Target = content.Target.GetComponent <StepTarget>(); helper.Task = task; helper.OnInit(); return(helper); } else { Log.Error(string.Format("步骤控制器:步骤 {0}.{1} 的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _currentContent.Helper)); } } return(null); }
/// <summary> /// 是否存在指定名称、类型的参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <param name="parameterType">参数类型</param> /// <returns>是否存在</returns> public bool IsExistParameter(string parameterName, StepParameter.ParameterType parameterType) { if (Parameters == null) { return(false); } else { StepParameter stepParameter = Parameters.Find((p) => { return(p.Name == parameterName && p.Type == parameterType); }); return(stepParameter != null); } }
/// <summary> /// 通过名称获取参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public StepParameter GetParameter(string parameterName) { StepParameter stepParameter = Parameters.Find((p) => { return(p.Name == parameterName); }); if (stepParameter != null) { return(stepParameter); } else { Log.Error(string.Format("步骤:{0}[ID:{1}]未获取到参数[{2}]!", Content.Name, Content.GUID, parameterName)); return(null); } }
/// <summary> /// 克隆 /// </summary> public StepParameter Clone() { StepParameter parameter = new StepParameter(); parameter.Type = Type; parameter.Name = Name; parameter.StringValue = StringValue; parameter.IntegerValue = IntegerValue; parameter.FloatValue = FloatValue; parameter.BooleanValue = BooleanValue; parameter.Vector2Value = Vector2Value; parameter.Vector3Value = Vector3Value; parameter.ColorValue = ColorValue; parameter.GameObjectValue = GameObjectValue; parameter.GameObjectGUID = GameObjectGUID; parameter.GameObjectPath = GameObjectPath; return(parameter); }
/// <summary> /// 通过名称获取参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> protected StepParameter GetParameter(string parameterName) { if (Parameters == null) { GlobalTools.LogError(string.Format("步骤:{0}[ID:{1}]未获取到参数[{2}]!", Content.Name, Content.GUID, parameterName)); return(null); } else { StepParameter stepParameter = Parameters.Find((p) => { return(p.Name == parameterName); }); if (stepParameter != null) { return(stepParameter); } else { GlobalTools.LogError(string.Format("步骤:{0}[ID:{1}]未获取到参数[{2}]!", Content.Name, Content.GUID, parameterName)); return(null); } } }
/// <summary> /// 克隆 /// </summary> /// <returns>新的对象</returns> internal StepParameter Clone() { StepParameter parameter = new StepParameter(); parameter.Type = Type; parameter.Name = Name; parameter.StringValue = StringValue; parameter.IntegerValue = IntegerValue; parameter.FloatValue = FloatValue; parameter.BooleanValue = BooleanValue; parameter.Vector2Value = Vector2Value; parameter.Vector3Value = Vector3Value; parameter.ColorValue = ColorValue; parameter.GameObjectValue = GameObjectValue; parameter.GameObjectGUID = GameObjectGUID; parameter.GameObjectPath = GameObjectPath; parameter.TextureValue = TextureValue; parameter.AudioClipValue = AudioClipValue; parameter.MaterialValue = MaterialValue; return(parameter); }
/// <summary> /// 通过名称获取AudioClip参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public AudioClip GetAudioClipParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.AudioClipValue : null); }
/// <summary> /// 通过名称获取Texture参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public Texture GetTextureParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.TextureValue : null); }
/// <summary> /// 通过名称获取GameObject参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public GameObject GetGameObjectParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.GameObjectValue : null); }
/// <summary> /// 通过名称获取Color参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public Color GetColorParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.ColorValue : Color.white); }
/// <summary> /// 通过名称获取Vector3参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public Vector3 GetVector3Parameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.Vector3Value : Vector3.zero); }
/// <summary> /// 通过名称获取Boolean参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public bool GetBooleanParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.BooleanValue : false); }
/// <summary> /// 通过名称获取Float参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public float GetFloatParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.FloatValue : 0f); }
/// <summary> /// 通过名称获取Integer参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public int GetIntegerParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.IntegerValue : 0); }
/// <summary> /// 通过名称获取Material参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public Material GetMaterialParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.MaterialValue : null); }
private void OnGUI() { GUILayout.BeginHorizontal("Toolbar"); if (GUILayout.Button(_content.Name, "Toolbarpopup")) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < _contentAsset.Content.Count; i++) { StepContent stepContent = _contentAsset.Content[i]; gm.AddItem(new GUIContent(i + "." + stepContent.Name), stepContent == _content, () => { _content = stepContent; }); } gm.ShowAsContext(); } if (GUILayout.Button(_content.Helper, "Toolbarbutton")) { if (_content.Helper != "<None>") { _stepEditorWindow.OpenHelperScript(_content.Helper); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginVertical("Box"); _scroll = GUILayout.BeginScrollView(_scroll); for (int i = 0; i < _content.Parameters.Count; i++) { StepParameter stepParameter = _content.Parameters[i]; GUILayout.BeginVertical("Helpbox"); GUILayout.BeginHorizontal(); GUILayout.Label("Type:", GUILayout.Width(40)); stepParameter.Type = (StepParameter.ParameterType)EditorGUILayout.EnumPopup(stepParameter.Type, GUILayout.Width(100)); GUILayout.FlexibleSpace(); if (GUILayout.Button("▲", "MiniButtonleft", GUILayout.Width(20))) { if (i > 0) { _content.Parameters.Remove(stepParameter); _content.Parameters.Insert(i - 1, stepParameter); continue; } } if (GUILayout.Button("▼", "MiniButtonmid", GUILayout.Width(20))) { if (i < _content.Parameters.Count - 1) { _content.Parameters.Remove(stepParameter); _content.Parameters.Insert(i + 1, stepParameter); continue; } } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", "Minibuttonright")) { _content.Parameters.RemoveAt(i); continue; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name:", GUILayout.Width(40)); stepParameter.Name = EditorGUILayout.TextField(stepParameter.Name); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Value:", GUILayout.Width(40)); switch (_content.Parameters[i].Type) { case StepParameter.ParameterType.String: stepParameter.StringValue = EditorGUILayout.TextField(stepParameter.StringValue); break; case StepParameter.ParameterType.Integer: stepParameter.IntegerValue = EditorGUILayout.IntField(stepParameter.IntegerValue); break; case StepParameter.ParameterType.Float: stepParameter.FloatValue = EditorGUILayout.FloatField(stepParameter.FloatValue); break; case StepParameter.ParameterType.Boolean: stepParameter.BooleanValue = EditorGUILayout.Toggle(stepParameter.BooleanValue); break; case StepParameter.ParameterType.Vector2: stepParameter.Vector2Value = EditorGUILayout.Vector2Field("", stepParameter.Vector2Value); break; case StepParameter.ParameterType.Vector3: stepParameter.Vector3Value = EditorGUILayout.Vector3Field("", stepParameter.Vector3Value); break; case StepParameter.ParameterType.Color: stepParameter.ColorValue = EditorGUILayout.ColorField(stepParameter.ColorValue); break; case StepParameter.ParameterType.GameObject: #region 步骤目标物体丢失,根据目标GUID重新搜寻 if (!stepParameter.GameObjectValue) { if (stepParameter.GameObjectGUID != "<None>") { stepParameter.GameObjectValue = GameObject.Find(stepParameter.GameObjectPath); if (!stepParameter.GameObjectValue) { StepTarget[] targets = FindObjectsOfType <StepTarget>(); foreach (StepTarget target in targets) { if (target.GUID == stepParameter.GameObjectGUID) { stepParameter.GameObjectValue = target.gameObject; stepParameter.GameObjectPath = target.transform.FullName(); break; } } } else { StepTarget target = stepParameter.GameObjectValue.GetComponent <StepTarget>(); if (!target) { target = stepParameter.GameObjectValue.AddComponent <StepTarget>(); target.GUID = stepParameter.GameObjectGUID; } } } } #endregion GUI.color = stepParameter.GameObjectValue ? Color.white : Color.gray; GameObject objValue = EditorGUILayout.ObjectField(stepParameter.GameObjectValue, typeof(GameObject), true) as GameObject; GUI.color = Color.white; #region 步骤目标改变 if (objValue != stepParameter.GameObjectValue) { if (objValue) { StepTarget target = objValue.GetComponent <StepTarget>(); if (!target) { target = objValue.AddComponent <StepTarget>(); } if (target.GUID == "<None>") { target.GUID = Guid.NewGuid().ToString(); } stepParameter.GameObjectValue = objValue; stepParameter.GameObjectGUID = target.GUID; stepParameter.GameObjectPath = objValue.transform.FullName(); } } #endregion break; } GUILayout.EndHorizontal(); if (_content.Parameters[i].Type == StepParameter.ParameterType.GameObject) { GUILayout.BeginHorizontal(); GUILayout.Label("GUID:", GUILayout.Width(40)); EditorGUILayout.TextField(_content.Parameters[i].GameObjectGUID); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear", "Minibutton", GUILayout.Width(40))) { _content.Parameters[i].GameObjectValue = null; _content.Parameters[i].GameObjectGUID = "<None>"; _content.Parameters[i].GameObjectPath = "<None>"; GUI.FocusControl(null); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add", "ButtonLeft")) { _content.Parameters.Add(new StepParameter()); } if (GUILayout.Button("Clear", "ButtonRight")) { if (EditorUtility.DisplayDialog("Prompt", "Are you sure delete all parameter?", "Yes", "No")) { _content.Parameters.Clear(); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Apply")) { GUI.FocusControl(null); EditorUtility.SetDirty(_contentAsset); } GUILayout.EndHorizontal(); }
/// <summary> /// 通过名称获取Vector2参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public Vector2 GetVector2Parameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName, StepParameter.ParameterType.Vector2); return((stepParameter != null) ? stepParameter.Vector2Value : Vector2.zero); }
/// <summary> /// 通过名称获取String参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public string GetStringParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName, StepParameter.ParameterType.String); return((stepParameter != null) ? stepParameter.StringValue : null); }
protected override void OnBodyGUI() { base.OnBodyGUI(); GUILayout.BeginVertical(EditorGlobalTools.Styles.Box); _scroll = GUILayout.BeginScrollView(_scroll); for (int i = 0; i < _content.Parameters.Count; i++) { StepParameter stepParameter = _content.Parameters[i]; GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); GUILayout.Label("Type:", GUILayout.Width(40)); stepParameter.Type = (StepParameter.ParameterType)EditorGUILayout.EnumPopup(stepParameter.Type, GUILayout.Width(100)); GUILayout.FlexibleSpace(); if (GUILayout.Button("▲", EditorStyles.miniButtonLeft, GUILayout.Width(20))) { if (i > 0) { _content.Parameters.Remove(stepParameter); _content.Parameters.Insert(i - 1, stepParameter); continue; } } if (GUILayout.Button("▼", EditorStyles.miniButtonMid, GUILayout.Width(20))) { if (i < _content.Parameters.Count - 1) { _content.Parameters.Remove(stepParameter); _content.Parameters.Insert(i + 1, stepParameter); continue; } } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", EditorStyles.miniButtonRight)) { _content.Parameters.RemoveAt(i); continue; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name:", GUILayout.Width(40)); stepParameter.Name = EditorGUILayout.TextField(stepParameter.Name); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Value:", GUILayout.Width(40)); switch (_content.Parameters[i].Type) { case StepParameter.ParameterType.String: stepParameter.StringValue = EditorGUILayout.TextField(stepParameter.StringValue); break; case StepParameter.ParameterType.Integer: stepParameter.IntegerValue = EditorGUILayout.IntField(stepParameter.IntegerValue); break; case StepParameter.ParameterType.Float: stepParameter.FloatValue = EditorGUILayout.FloatField(stepParameter.FloatValue); break; case StepParameter.ParameterType.Boolean: stepParameter.BooleanValue = EditorGUILayout.Toggle(stepParameter.BooleanValue); break; case StepParameter.ParameterType.Vector2: stepParameter.Vector2Value = EditorGUILayout.Vector2Field("", stepParameter.Vector2Value); break; case StepParameter.ParameterType.Vector3: stepParameter.Vector3Value = EditorGUILayout.Vector3Field("", stepParameter.Vector3Value); break; case StepParameter.ParameterType.Color: stepParameter.ColorValue = EditorGUILayout.ColorField(stepParameter.ColorValue); break; case StepParameter.ParameterType.GameObject: #region 步骤目标物体丢失,根据目标GUID重新搜寻 if (!stepParameter.GameObjectValue) { if (stepParameter.GameObjectGUID != "<None>") { stepParameter.GameObjectValue = GameObject.Find(stepParameter.GameObjectPath); if (!stepParameter.GameObjectValue) { StepTarget[] targets = FindObjectsOfType <StepTarget>(); foreach (StepTarget target in targets) { if (target.GUID == stepParameter.GameObjectGUID) { stepParameter.GameObjectValue = target.gameObject; stepParameter.GameObjectPath = target.transform.FullName(); break; } } } else { StepTarget target = stepParameter.GameObjectValue.GetComponent <StepTarget>(); if (!target) { target = stepParameter.GameObjectValue.AddComponent <StepTarget>(); target.GUID = stepParameter.GameObjectGUID; } } } } #endregion GUI.color = stepParameter.GameObjectValue ? Color.white : Color.gray; GameObject objValue = EditorGUILayout.ObjectField(stepParameter.GameObjectValue, typeof(GameObject), true) as GameObject; GUI.color = Color.white; #region 步骤目标改变 if (objValue != stepParameter.GameObjectValue) { if (objValue) { StepTarget target = objValue.GetComponent <StepTarget>(); if (!target) { target = objValue.AddComponent <StepTarget>(); } if (target.GUID == "<None>") { target.GUID = Guid.NewGuid().ToString(); } stepParameter.GameObjectValue = objValue; stepParameter.GameObjectGUID = target.GUID; stepParameter.GameObjectPath = objValue.transform.FullName(); } } #endregion break; case StepParameter.ParameterType.Texture: GUI.color = stepParameter.TextureValue ? Color.white : Color.gray; stepParameter.TextureValue = EditorGUILayout.ObjectField(stepParameter.TextureValue, typeof(Texture), false) as Texture; GUI.color = Color.white; break; case StepParameter.ParameterType.AudioClip: GUI.color = stepParameter.AudioClipValue ? Color.white : Color.gray; stepParameter.AudioClipValue = EditorGUILayout.ObjectField(stepParameter.AudioClipValue, typeof(AudioClip), false) as AudioClip; GUI.color = Color.white; break; case StepParameter.ParameterType.Material: GUI.color = stepParameter.MaterialValue ? Color.white : Color.gray; stepParameter.MaterialValue = EditorGUILayout.ObjectField(stepParameter.MaterialValue, typeof(Material), false) as Material; GUI.color = Color.white; break; } GUILayout.EndHorizontal(); if (_content.Parameters[i].Type == StepParameter.ParameterType.GameObject) { GUILayout.BeginHorizontal(); GUILayout.Label("GUID:", GUILayout.Width(40)); EditorGUILayout.TextField(_content.Parameters[i].GameObjectGUID); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear", EditorStyles.miniButton, GUILayout.Width(40))) { _content.Parameters[i].GameObjectValue = null; _content.Parameters[i].GameObjectGUID = "<None>"; _content.Parameters[i].GameObjectPath = "<None>"; GUI.FocusControl(null); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add", EditorGlobalTools.Styles.ButtonLeft)) { _content.Parameters.Add(new StepParameter()); } if (GUILayout.Button("Clear", EditorGlobalTools.Styles.ButtonRight)) { if (EditorUtility.DisplayDialog("Prompt", "Are you sure delete all parameter?", "Yes", "No")) { _content.Parameters.Clear(); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Apply")) { GUI.FocusControl(null); EditorUtility.SetDirty(_contentAsset); } GUILayout.EndHorizontal(); }
/// <summary> /// 是否存在指定名称的参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>是否存在</returns> public bool IsExistParameter(string parameterName) { StepParameter stepParameter = Parameters.Find((p) => { return(p.Name == parameterName); }); return(stepParameter != null); }
/// <summary> /// 通过名称获取String参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> public string GetStringParameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.StringValue : ""); }
/// <summary> /// 通过名称获取Vector2参数 /// </summary> /// <param name="parameterName">参数名称</param> /// <returns>参数</returns> protected Vector2 GetVector2Parameter(string parameterName) { StepParameter stepParameter = GetParameter(parameterName); return((stepParameter != null) ? stepParameter.Vector2Value : Vector2.zero); }