public GPCondition AddCondition(System.Type type, EventHandler handler) { if (handler == null) { throw new System.ArgumentNullException(); } if (!typeof(GPCondition).IsAssignableFrom(type)) { throw new System.ArgumentException("Type " + type.FullName + " must inherit from GPCondition"); } GameObject holder; if (!m_actionObjectMap.Dictionary.TryGetValue(handler, out holder)) { holder = AddEventHandler(handler); } GPCondition condition = (GPCondition)holder.AddComponent(type); condition.SetHandler(handler); return(condition); }
protected override void OnInspectorGUI() { GPConditionNOT condition = (GPConditionNOT)Condition; EditorGUI.indentLevel++; EditorGUILayout.LabelField("NOT", EditorStyles.toolbarButton, GUILayout.Width(200), GUILayout.Height(30)); GPCondition cA = condition.A; m_selectedAIndex = GPConditionInspector.CreateConditionField(ref cA, m_selectedAIndex, condition.Handler); condition.A = cA; if (m_aInspector == null && condition.A != null) { m_aInspector = GPConditionInspector.CreateInspector(condition.A); } if (m_aInspector != null) { m_aInspector.DrawInspector(); } EditorGUI.indentLevel--; }
public static GPCondition AddCondition(System.Type type, EventHandler handler) { GPCondition condition = (GPCondition)handler.GetGPActionObjectMapperOrCreate().AddCondition(type, handler); condition.SetHandler(handler); return(condition); }
public static GPConditionInspector CreateInspector(GPCondition condition) { GPConditionInspector insp = (GPConditionInspector)System.Activator.CreateInstance( GPConditionInspectorManager.InspectorTypeForCondition(condition)); insp.Condition = condition; return(insp); }
public static System.Type InspectorTypeForCondition(GPCondition condition) { System.Type conditionType = condition.GetType(); System.Type inspectorType = null; while (inspectorType == null && conditionType != typeof(GPCondition)) { if (s_gpconditionInspectorMap.TryGetValue(conditionType, out inspectorType)) { return(inspectorType); } conditionType = conditionType.BaseType; } return(typeof(GPConditionDefaultInspector)); }
public static int CreateConditionField(ref GPCondition condition, int selectedIndex, EventHandler handler) { if (condition != null) { return(selectedIndex); } EditorGUILayout.BeginHorizontal(); int idx = EditorGUILayout.Popup(selectedIndex, GPConditionManager.s_gpconditionTypeNames); if (GUILayout.Button("Add")) { condition = AddCondition(GPConditionManager.s_gpconditionTypes[idx], handler); } EditorGUILayout.EndHorizontal(); return(idx); }