public bool AddVariable(Variable variable) { if (variable == null) return false; if (m_Variables.ContainsKey(variable.m_Name)) return false; variable.m_GameObject = gameObject; m_Variables.Add(variable.m_Name, variable); return true; }
public bool Load(RuleBaseType ruleBase) { Clear(); int variableCount = ruleBase.GetVariablesCount(); for (int i = 0; i < variableCount; i++) { Variable variable = new Variable(gameObject, ruleBase.GetVariablesAt(i)); AddVariable(variable); } return true; }
public bool GetVariable(string name, out Variable variable) { variable = null; if (name.Length == 0) return false; if (!m_Variables.ContainsKey(name)) return false; variable = m_Variables[name]; if (variable == null) return false; return true; }
public void ShowStateGUI() { GUI.backgroundColor = new Color(0.8f,0.8f,1); GUILayout.BeginHorizontal(); if (m_EditMode == EditMode.Nothing) { if (GUILayout.Button("Add Variable", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { m_EditMode = EditMode.AddNewVariable; m_EditVariable = new Variable(); m_EditVariable.m_GameObject = gameObject; m_AttachScript = false; } } else { if (GUILayout.Button("Cancel", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { m_EditVariable.RemoveScript(); m_EditMode = EditMode.Nothing; m_EditVariable = new Variable(); m_EditVariable.m_GameObject = gameObject; } } if ((m_EditMode == EditMode.AddNewVariable || m_EditMode == EditMode.EditExistingVariable) && GUILayout.Button("Ok", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { if (m_EditMode == EditMode.AddNewVariable) { if (!HasVariable(m_EditVariable.m_Name) && m_EditVariable.m_Name != "") { Variable newVariable = new Variable(m_EditVariable) ; AddVariable(newVariable); m_EditMode = EditMode.Nothing; } else { EditorUtility.DisplayDialog("Error", "There is already a variable with this name in this state. Please give the variable a unique name to be called from", "Ok"); } } else { Variable newVariable = new Variable(m_EditVariable.m_Name, m_EditVariable.GetValue()); newVariable.m_GameObject = gameObject; if (m_AttachScript) { newVariable.SetScript(m_EditVariable.m_UpdateScript); } SetVariable(newVariable); m_EditMode = EditMode.Nothing; } } GUILayout.FlexibleSpace(); float nameWidth = 100; float typeWidth = 100; float valueWidth = 60; float scriptWidth = 180; EditorGUIUtility.labelWidth = 80; m_DebugMode = EditorGUILayout.Toggle("DebugMode: ", m_DebugMode, GUILayout.MaxWidth (95)); GUILayout.EndHorizontal (); GUILayout.BeginHorizontal(); GUI.color = Color.yellow; GUILayout.Label("Name", GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Type", GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Value", GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Script", GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); GUI.color = Color.white; GUILayout.EndHorizontal(); if (m_EditMode == EditMode.AddNewVariable || m_EditMode == EditMode.EditExistingVariable) { GUILayout.BeginHorizontal(); if (m_EditMode == EditMode.AddNewVariable) m_EditVariable.m_Name = EditorGUILayout.TextField(m_EditVariable.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); else EditorGUILayout.LabelField(m_EditVariable.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); VariableType variableType = (VariableType)EditorGUILayout.EnumPopup(m_EditVariable.GetVariableType(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (variableType != m_EditVariable.GetVariableType()) { m_EditVariable.SetVariableType(variableType); m_AttachScript = false; } if (m_EditVariable.GetVariableType () == VariableType.BOOLEAN) { int index = (bool)m_EditVariable.GetValue() ? 1 : 0; index = EditorGUILayout.Popup(index, m_BooleanStrings, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); m_EditVariable.SetValue(index == 1 ? true : false); } else if (m_EditVariable.GetVariableType() == VariableType.STRING) { string stringValue = (string)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.TextArea(stringValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } else if (m_EditVariable.GetVariableType() == VariableType.INT) { int intValue = (int)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.IntField((int)intValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } else if (m_EditVariable.GetVariableType() == VariableType.FLOAT) { float floatValue = (float)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.FloatField(floatValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } if (m_AttachScript = EditorGUILayout.Toggle(m_AttachScript, GUILayout.MaxWidth(10))) { List<ScriptDescriptor> sensorScripts = ScriptManager.GetScriptsByType(typeof(BaseSensor)); List<ScriptDescriptor> filteredSensorScripts = new List<ScriptDescriptor>(); List<String> sensorScriptNames = new List<String>(); for (int i = 0; i < sensorScripts.Count(); i++) { if (sensorScripts[i].m_ReturnType.ToUpper() == m_EditVariable.GetVariableType().ToString()) { filteredSensorScripts.Add(sensorScripts[i]); sensorScriptNames.Add(sensorScripts[i].m_Name); } } if (filteredSensorScripts.Count == 0) { EditorGUILayout.HelpBox("None of the sensor scripts return a type compatible with this variable type", MessageType.Info); } else { int sensorScriptIndex = -1; if (m_EditVariable.m_UpdateScriptType != null) sensorScriptIndex = filteredSensorScripts.FindIndex(sensorScript => sensorScript.m_Type == m_EditVariable.m_UpdateScriptType); int newSensorScriptIndex = EditorGUILayout.Popup(Mathf.Max(sensorScriptIndex, 0), sensorScriptNames.ToArray(), GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); if ((newSensorScriptIndex > -1) && (newSensorScriptIndex != sensorScriptIndex)) { m_EditVariable.SetScript(filteredSensorScripts.ElementAtOrDefault(newSensorScriptIndex).m_Type); if (m_DebugMode) Debug.Log("Updating AttachedScript: " + filteredSensorScripts.ElementAt(newSensorScriptIndex).m_Name); } } } else m_EditVariable.RemoveScript(); GUILayout.EndHorizontal(); if (m_AttachScript && m_EditVariable.HasScript()) { m_EditVariable.m_UpdateScript.ShowScriptGUI(); } } if (m_Variables.Count == 0) { EditorGUILayout.HelpBox("There are no variables in this state. Add some with the Add Variable button", MessageType.Info); } foreach (KeyValuePair<string, Variable> pair in m_Variables.ToArray()) { if (pair.Value != null) { GUILayout.BeginHorizontal(); GUI.color = Color.white; GUI.backgroundColor = Color.white; if (Application.isPlaying) { GUILayout.Label(pair.Value.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label(pair.Value.GetType().ToString(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (pair.Value.GetValue() != null) GUILayout.Label(pair.Value.GetValue().ToString(), GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); else GUILayout.Label("", GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); if (pair.Value.HasScript()) { ScriptNameAttribute nameAttribute = pair.Value.m_UpdateScriptType.GetCustomAttributes(typeof(ScriptNameAttribute), false).FirstOrDefault() as ScriptNameAttribute; GUILayout.Label(nameAttribute.name, GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); } } else { GUILayout.Label(pair.Value.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label(pair.Value.GetTypeString(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (pair.Value.GetValue() != null) GUILayout.Label(pair.Value.GetValue().ToString(), GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); if (pair.Value.HasScript()) { ScriptNameAttribute nameAttribute = pair.Value.m_UpdateScriptType.GetCustomAttributes(typeof(ScriptNameAttribute), false).FirstOrDefault() as ScriptNameAttribute; GUILayout.Label(nameAttribute.name, GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); } GUILayout.FlexibleSpace(); //Set layout passed this point to align to the right GUI.backgroundColor = new Color(0.6f, 1f, 0.6f); if (GUILayout.Button("E", GUILayout.MaxWidth(20))) { EditVariable(pair.Value); } GUI.backgroundColor = new Color(1,0.6f,0.6f); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (EditorUtility.DisplayDialog("Delete Variable " + pair.Value.m_Name, "Are you sure?", "Yes", "No")) { pair.Value.RemoveScript(); RemoveVariable(pair.Value.m_Name); } } } GUILayout.EndHorizontal(); } } GUI.backgroundColor = Color.white; GUI.color = Color.white; }
public void EditVariable(Variable editVariable) { m_EditVariable = editVariable; m_EditMode = EditMode.EditExistingVariable; m_AttachScript = editVariable.HasScript(); }
public bool SetVariable(Variable variable) { if (!m_Variables.ContainsKey(variable.m_Name)) return false; m_Variables[variable.m_Name] = variable; return true; }
public override bool Execute() { Variable var = new Variable(); Go.GetComponent<State>().GetVariable("Agressivite", out var); float retour = (float)var.GetValue(); int race = 0; if (Go.GetComponent<Element>().camp == "Ours") { race = 0; } else { race = 1; } if (Chargement_jeu.buildTurn) { if (retour < 40) { Batiment.aggressivite = retour; Batiment.defense = 75; Batiment.technologie = 25; } else if (retour < 70 && retour >= 40) { Batiment.aggressivite = retour; Batiment.defense = 50; Batiment.technologie = 50; } else if (retour > 70) { Batiment.aggressivite = retour; Batiment.defense = 25; Batiment.technologie = 75; } } Production prod = null; Production rech = null; if (race == 0) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][1]; Score.ressourcediv_IA[race][1] -= Score.ressourcediv_IA[race][1]; if (retour <= 33) { if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Ours de guerre", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 200) { prod = new Production("Ours Blanc", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 50) { prod = new Production("Ourson", this.gameObject); } if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Endurance Mystique", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Griffes Enchantees", this.gameObject); Production.is_done[race][0] = true; } } } else if (retour > 33 && retour < 40) { if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Ours de guerre", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 200) { prod = new Production("Ours Blanc", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 50) { prod = new Production("Ourson", this.gameObject); } if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Endurance Mystique", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Griffes Enchantees", this.gameObject); Production.is_done[race][0] = true; } } } else if (retour >= 40 && retour < 70) { if (Score.ressourcediv_IA[race][0] > 200) { prod = new Production("Ours Blanc", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Ours de guerre", this.gameObject); } if (Score.ressourcediv_IA[race][2] <= 750) { if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1]&& Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Endurance Mystique", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0]&& Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Griffes Enchantees", this.gameObject); Production.is_done[race][0] = true; } } } } else if (retour >= 70) { if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Ours de guerre", this.gameObject); } if (Score.ressourcediv_IA[race][2] <= 750) { if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Endurance Mystique", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Griffes Enchantees", this.gameObject); Production.is_done[race][0] = true; } } } } } else if (race == 1) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][1]; Score.ressourcediv_IA[race][1] -= Score.ressourcediv_IA[race][1]; if (retour < 33) { if (Score.ressourcediv_IA[race][0] <= 50) { prod = new Production("Poulpy", this.gameObject); } else if (Score.ressourcediv_IA[race][0] <= 200) { prod = new Production("Octopus", this.gameObject); } else if (Score.ressourcediv_IA[race][0] <= 350) { prod = new Production("Cyber-Poulpe", this.gameObject); } if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Plasma Defensif", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Ventouses Laser", this.gameObject); Production.is_done[race][0] = true; } } } else if (retour >= 33 && retour < 40) { if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Cyber-Poulpe", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 200) { prod = new Production("Octopus", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 50) { prod = new Production("Poulpy", this.gameObject); } if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Plasma Defensif", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Ventouses Laser", this.gameObject); Production.is_done[race][0] = true; } } } else if (retour >= 40 && retour < 70) { if (Score.ressourcediv_IA[race][0] > 200) { prod = new Production("Octopus", this.gameObject); } else if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Cyber-Poulpe", this.gameObject); } if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1] && Score.ressourcediv_IA[race][2] >= 750) { rech = new Production("Plasma Defensif", this.gameObject); Production.is_done[race][1] = true; } else if (!Production.is_done[race][0] && Score.ressourcediv_IA[race][2] >= 500) { rech = new Production("Ventouses Laser", this.gameObject); Production.is_done[race][0] = true; } } } else if (retour >= 70) { if (Score.ressourcediv_IA[race][0] > 350) { prod = new Production("Cyber-Poulpe", this.gameObject); } if (Score.ressourcediv_IA[race][2] <= 750) { if (Production.is_done[race][0] && Production.is_done[race][1]) { Score.ressourcediv_IA[race][0] += Score.ressourcediv_IA[race][2]; Score.ressourcediv_IA[race][2] -= Score.ressourcediv_IA[race][2]; } else { if (!Production.is_done[race][1]) { rech = new Production("Plasma Defensif", this.gameObject); Production.is_done[race][1] = true; } else { rech = new Production("Ventouses Laser", this.gameObject); Production.is_done[race][0] = true; } } } } } if (prod != null) { Score.ressourcediv_IA[race][0] -= prod.cout; prod.launchProduce(); } if (rech != null) { Score.ressourcediv_IA[race][2] -= rech.cout; rech.launchProduce(); } return true; }
public void ShowStateGUI() { GUI.backgroundColor = new Color(0.8f, 0.8f, 1); GUILayout.BeginHorizontal(); if (m_EditMode == EditMode.Nothing) { if (GUILayout.Button("Add Variable", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { m_EditMode = EditMode.AddNewVariable; m_EditVariable = new Variable(); m_EditVariable.m_GameObject = gameObject; m_AttachScript = false; } } else { if (GUILayout.Button("Cancel", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { m_EditVariable.RemoveScript(); m_EditMode = EditMode.Nothing; m_EditVariable = new Variable(); m_EditVariable.m_GameObject = gameObject; } } if ((m_EditMode == EditMode.AddNewVariable || m_EditMode == EditMode.EditExistingVariable) && GUILayout.Button("Ok", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { if (m_EditMode == EditMode.AddNewVariable) { if (!HasVariable(m_EditVariable.m_Name) && m_EditVariable.m_Name != "") { Variable newVariable = new Variable(m_EditVariable); AddVariable(newVariable); m_EditMode = EditMode.Nothing; } else { EditorUtility.DisplayDialog("Error", "There is already a variable with this name in this state. Please give the variable a unique name to be called from", "Ok"); } } else { Variable newVariable = new Variable(m_EditVariable.m_Name, m_EditVariable.GetValue()); newVariable.m_GameObject = gameObject; if (m_AttachScript) { newVariable.SetScript(m_EditVariable.m_UpdateScript); } SetVariable(newVariable); m_EditMode = EditMode.Nothing; } } GUILayout.FlexibleSpace(); float nameWidth = 100; float typeWidth = 100; float valueWidth = 60; float scriptWidth = 180; EditorGUIUtility.labelWidth = 80; m_DebugMode = EditorGUILayout.Toggle("DebugMode: ", m_DebugMode, GUILayout.MaxWidth(95)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.color = Color.yellow; GUILayout.Label("Name", GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Type", GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Value", GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); GUILayout.Label("Script", GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); GUI.color = Color.white; GUILayout.EndHorizontal(); if (m_EditMode == EditMode.AddNewVariable || m_EditMode == EditMode.EditExistingVariable) { GUILayout.BeginHorizontal(); if (m_EditMode == EditMode.AddNewVariable) { m_EditVariable.m_Name = EditorGUILayout.TextField(m_EditVariable.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); } else { EditorGUILayout.LabelField(m_EditVariable.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); } VariableType variableType = (VariableType)EditorGUILayout.EnumPopup(m_EditVariable.GetVariableType(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (variableType != m_EditVariable.GetVariableType()) { m_EditVariable.SetVariableType(variableType); m_AttachScript = false; } if (m_EditVariable.GetVariableType() == VariableType.BOOLEAN) { int index = (bool)m_EditVariable.GetValue() ? 1 : 0; index = EditorGUILayout.Popup(index, m_BooleanStrings, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); m_EditVariable.SetValue(index == 1 ? true : false); } else if (m_EditVariable.GetVariableType() == VariableType.STRING) { string stringValue = (string)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.TextArea(stringValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } else if (m_EditVariable.GetVariableType() == VariableType.INT) { int intValue = (int)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.IntField((int)intValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } else if (m_EditVariable.GetVariableType() == VariableType.FLOAT) { float floatValue = (float)m_EditVariable.GetValue(); m_EditVariable.SetValue(EditorGUILayout.FloatField(floatValue, GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false))); } if (m_AttachScript = EditorGUILayout.Toggle(m_AttachScript, GUILayout.MaxWidth(10))) { List <ScriptDescriptor> sensorScripts = ScriptManager.GetScriptsByType(typeof(BaseSensor)); List <ScriptDescriptor> filteredSensorScripts = new List <ScriptDescriptor>(); List <String> sensorScriptNames = new List <String>(); for (int i = 0; i < sensorScripts.Count(); i++) { if (sensorScripts[i].m_ReturnType.ToUpper() == m_EditVariable.GetVariableType().ToString()) { filteredSensorScripts.Add(sensorScripts[i]); sensorScriptNames.Add(sensorScripts[i].m_Name); } } if (filteredSensorScripts.Count == 0) { EditorGUILayout.HelpBox("None of the sensor scripts return a type compatible with this variable type", MessageType.Info); } else { int sensorScriptIndex = -1; if (m_EditVariable.m_UpdateScriptType != null) { sensorScriptIndex = filteredSensorScripts.FindIndex(sensorScript => sensorScript.m_Type == m_EditVariable.m_UpdateScriptType); } int newSensorScriptIndex = EditorGUILayout.Popup(Mathf.Max(sensorScriptIndex, 0), sensorScriptNames.ToArray(), GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); if ((newSensorScriptIndex > -1) && (newSensorScriptIndex != sensorScriptIndex)) { m_EditVariable.SetScript(filteredSensorScripts.ElementAtOrDefault(newSensorScriptIndex).m_Type); if (m_DebugMode) { Debug.Log("Updating AttachedScript: " + filteredSensorScripts.ElementAt(newSensorScriptIndex).m_Name); } } } } else { m_EditVariable.RemoveScript(); } GUILayout.EndHorizontal(); if (m_AttachScript && m_EditVariable.HasScript()) { m_EditVariable.m_UpdateScript.ShowScriptGUI(); } } if (m_Variables.Count == 0) { EditorGUILayout.HelpBox("There are no variables in this state. Add some with the Add Variable button", MessageType.Info); } foreach (KeyValuePair <string, Variable> pair in m_Variables.ToArray()) { if (pair.Value != null) { GUILayout.BeginHorizontal(); GUI.color = Color.white; GUI.backgroundColor = Color.white; if (Application.isPlaying) { GUILayout.Label(pair.Value.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label(pair.Value.GetType().ToString(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (pair.Value.GetValue() != null) { GUILayout.Label(pair.Value.GetValue().ToString(), GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); } else { GUILayout.Label("", GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); } if (pair.Value.HasScript()) { ScriptNameAttribute nameAttribute = pair.Value.m_UpdateScriptType.GetCustomAttributes(typeof(ScriptNameAttribute), false).FirstOrDefault() as ScriptNameAttribute; GUILayout.Label(nameAttribute.name, GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); } } else { GUILayout.Label(pair.Value.m_Name, GUILayout.MaxWidth(nameWidth), GUILayout.MinWidth(nameWidth), GUILayout.ExpandWidth(false)); GUILayout.Label(pair.Value.GetTypeString(), GUILayout.MaxWidth(typeWidth), GUILayout.MinWidth(typeWidth), GUILayout.ExpandWidth(false)); if (pair.Value.GetValue() != null) { GUILayout.Label(pair.Value.GetValue().ToString(), GUILayout.MaxWidth(valueWidth), GUILayout.MinWidth(valueWidth), GUILayout.ExpandWidth(false)); } if (pair.Value.HasScript()) { ScriptNameAttribute nameAttribute = pair.Value.m_UpdateScriptType.GetCustomAttributes(typeof(ScriptNameAttribute), false).FirstOrDefault() as ScriptNameAttribute; GUILayout.Label(nameAttribute.name, GUILayout.MaxWidth(scriptWidth), GUILayout.MinWidth(scriptWidth), GUILayout.ExpandWidth(false)); } GUILayout.FlexibleSpace(); //Set layout passed this point to align to the right GUI.backgroundColor = new Color(0.6f, 1f, 0.6f); if (GUILayout.Button("E", GUILayout.MaxWidth(20))) { EditVariable(pair.Value); } GUI.backgroundColor = new Color(1, 0.6f, 0.6f); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (EditorUtility.DisplayDialog("Delete Variable " + pair.Value.m_Name, "Are you sure?", "Yes", "No")) { pair.Value.RemoveScript(); RemoveVariable(pair.Value.m_Name); } } } GUILayout.EndHorizontal(); } } GUI.backgroundColor = Color.white; GUI.color = Color.white; }
public bool IsEqual(Variable rhs) { return (m_Name == rhs.m_Name); }
public void Assign(Variable rhs) { m_Name = rhs.m_Name; m_Type = rhs.m_Type; m_Value = rhs.m_Value; m_UpdateScriptType = rhs.m_UpdateScriptType; m_UpdateScript = rhs.m_UpdateScript; m_IsDirty = rhs.m_IsDirty; m_GameObject = rhs.m_GameObject; }
public Variable(Variable copy) { Assign(copy); }
public override bool Execute() { ele = Go.GetComponent<Unite>(); deplacement = ele.deplacement; mouvement = ele.mouvement; State etat = Go.GetComponent<State>(); Variable var = new Variable(); etat.GetVariable("prox", out var); if ((int)var.GetValue() == 1) { if (!calcule) { direction = 1; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); deplacement = ele.deplacement; calcule = true; init=1; } } else if ((int)var.GetValue() == 2) { if (!calcule) { direction = 2; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); calcule = true; if (Go.GetComponent<Element>().camp == "Ours") { Score.ressource_IA[0] += Unite.stockage*init; Score.ressourcediv_IA[0][0] += Unite.stockage*init * Batiment.aggressivite / 100; Score.ressourcediv_IA[0][1] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[0][2] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } else if (Go.GetComponent<Element>().camp == "Poulpe") { Score.ressource_IA[1] += Unite.stockage*init; Score.ressourcediv_IA[1][0] += Unite.stockage *init* Batiment.aggressivite / 100; Score.ressourcediv_IA[1][1] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[1][2] += Unite.stockage *init* (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } } } else if ((int)var.GetValue() == 0) { calcule = false; } if (deplacement != null) { if (deplacement.Count != 0) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + Go.transform.position.x - 0.5), (int)(j + Go.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent<Case>().occupe = false; ele.list_case[i, j].GetComponent<Case>().element = null; } } StartCoroutine("MoveTowards"); } else { Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); mouvement = 0; } } return true; }
public static void setVariable(GameObject objet, string scriptName) { if (scriptName.Equals("EnemyDetector")) { InferenceEngine infe = objet.GetComponent<InferenceEngine>(); Variable var = new Variable("nb_enn", objet.GetComponent<EnemyDetector>().compteurDetection); infe.GetState().SetVariable(var); } }