namespace Zinnia.Utility { using UnityEditor; using UnityEngine; using Zinnia.Action; using Zinnia.Action.Collection; using Zinnia.Association; using Zinnia.Association.Collection; using Zinnia.Data.Collection; using Zinnia.Data.Collection.List; using Zinnia.Data.Type.Transformation.Aggregation; using Zinnia.Event; using Zinnia.Haptics; using Zinnia.Haptics.Collection; using Zinnia.Pattern.Collection; using Zinnia.Process.Moment; using Zinnia.Process.Moment.Collection; using Zinnia.Rule; using Zinnia.Rule.Collection; using Zinnia.Tracking.Modification; using Zinnia.Tracking.Velocity; using Zinnia.Tracking.Velocity.Collection; using Zinnia.Visual; [InitializeOnLoad] public class ObservableListComponentGeneratorEditorWindow : EditorWindow { protected enum OptionType { ActionRegistrar, AllAction, AllRule, AnyAction, AnyRule, AnyBehaviourEnabledRule, AnyComponentTypeRule, AnyTagRule, BehaviourEnabledObserver, CompositeProcess, FloatAdder, FloatMaxFinder, FloatMeanFinder, FloatMedianFinder, FloatMinFinder, FloatModeFinder, FloatMultiplier, FloatRangeFinder, FloatSubtractor, GameObjectsAssociationActivator, GameObjectRelations, GameObjectStateSwitcher, HapticProcessor, ListContainsRule, MeshStateModifier, MomentProcessor, PatternMatcherRule, RuleAssociation, RulesMatcher, Vector2Adder, Vector2Multiplier, Vector2Subtractor, Vector3Adder, Vector3Multiplier, Vector3Subtractor, VelocityTrackerProcessor } private const string windowTitle = "Observable List Component Generator"; private static EditorWindow promptWindow; private Vector2 scrollPosition; private OptionType selectedOption; private bool nestInSelectedObject = true; private GameObject selectedObject; private string containerName = ""; public void OnGUI() { selectedObject = Selection.activeGameObject; using (GUILayout.ScrollViewScope scrollViewScope = new GUILayout.ScrollViewScope(scrollPosition)) { scrollPosition = scrollViewScope.scrollPosition; GUILayout.Label("Generate New Multi-Part Component", EditorStyles.boldLabel); selectedOption = (OptionType)EditorGUILayout.EnumPopup("Component Type", selectedOption); containerName = EditorGUILayout.TextField("Override Container Name", containerName); if (selectedObject != null) { string nestLabel = string.Format("Generate in [{0}]", selectedObject.name); nestInSelectedObject = EditorGUILayout.Toggle(new GUIContent(nestLabel, nestLabel), nestInSelectedObject); } EditorHelper.DrawHorizontalLine(); if (GUILayout.Button("Generate Component")) { CreateComponent(selectedOption); } } } protected virtual void CreateComponent(OptionType selectedOption) { GameObject componentContainer = new GameObject(string.IsNullOrEmpty(containerName) ? selectedOption.ToString() + "_Container" : containerName); if (selectedObject != null && nestInSelectedObject) { componentContainer.transform.SetParent(selectedObject.transform); } GameObject listContainer = new GameObject("ListContainer"); listContainer.transform.SetParent(componentContainer.transform); switch (selectedOption) { case OptionType.AllRule: AllRule allRule = componentContainer.AddComponent(); RuleContainerObservableList allList = listContainer.AddComponent(); allRule.Rules = allList; break; case OptionType.AnyRule: AnyRule anyRule = componentContainer.AddComponent(); RuleContainerObservableList anyList = listContainer.AddComponent(); anyRule.Rules = anyList; break; case OptionType.AnyBehaviourEnabledRule: AnyBehaviourEnabledRule behaviourRule = componentContainer.AddComponent(); SerializableTypeBehaviourObservableList behaviourList = listContainer.AddComponent(); behaviourRule.BehaviourTypes = behaviourList; break; case OptionType.AnyComponentTypeRule: AnyComponentTypeRule componentRule = componentContainer.AddComponent(); SerializableTypeComponentObservableList componentList = listContainer.AddComponent(); componentRule.ComponentTypes = componentList; break; case OptionType.AnyTagRule: AnyTagRule tagRule = componentContainer.AddComponent(); StringObservableList tagList = listContainer.AddComponent(); tagRule.Tags = tagList; break; case OptionType.BehaviourEnabledObserver: BehaviourEnabledObserver behaviourEnabledObserver = componentContainer.AddComponent(); BehaviourObservableList behaviourObservableList = listContainer.AddComponent(); behaviourEnabledObserver.Behaviours = behaviourObservableList; break; case OptionType.ListContainsRule: ListContainsRule listRule = componentContainer.AddComponent(); UnityObjectObservableList listList = listContainer.AddComponent(); listRule.Objects = listList; break; case OptionType.RulesMatcher: RulesMatcher matcherRule = componentContainer.AddComponent(); RulesMatcherElementObservableList matcherList = listContainer.AddComponent(); matcherRule.Elements = matcherList; break; case OptionType.ActionRegistrar: ActionRegistrar actionRegistrar = componentContainer.AddComponent(); ActionRegistrarSourceObservableList registrarList = listContainer.AddComponent(); GameObjectObservableList limitsList = listContainer.AddComponent(); actionRegistrar.Sources = registrarList; actionRegistrar.SourceLimits = limitsList; break; case OptionType.AllAction: AllAction allAction = componentContainer.AddComponent(); ActionObservableList allActionList = listContainer.AddComponent(); allAction.Actions = allActionList; break; case OptionType.AnyAction: AnyAction anyAction = componentContainer.AddComponent(); ActionObservableList anyActionList = listContainer.AddComponent(); anyAction.Actions = anyActionList; break; case OptionType.GameObjectsAssociationActivator: GameObjectsAssociationActivator gameObjectsAssociationActivator = componentContainer.AddComponent(); GameObjectsAssociationObservableList gameObjectsAssociationList = listContainer.AddComponent(); gameObjectsAssociationActivator.Associations = gameObjectsAssociationList; break; case OptionType.GameObjectRelations: GameObjectRelations gameObjectRelations = componentContainer.AddComponent(); GameObjectRelationObservableList gameObjectsRelationsList = listContainer.AddComponent(); gameObjectRelations.Relations = gameObjectsRelationsList; break; case OptionType.GameObjectStateSwitcher: GameObjectStateSwitcher gameObjectStateSwitcher = componentContainer.AddComponent(); GameObjectObservableList gameObjectsList = listContainer.AddComponent(); gameObjectStateSwitcher.Targets = gameObjectsList; break; case OptionType.PatternMatcherRule: PatternMatcherRule patternMatcherRule = componentContainer.AddComponent(); PatternMatcherObservableList patternMatcherList = listContainer.AddComponent(); patternMatcherRule.Patterns = patternMatcherList; break; case OptionType.RuleAssociation: RuleAssociation ruleAssociation = componentContainer.AddComponent(); GameObjectObservableList ruleAssociationGameObjectsList = listContainer.AddComponent(); ruleAssociation.GameObjects = ruleAssociationGameObjectsList; break; case OptionType.HapticProcessor: HapticProcessor hapticProcessor = componentContainer.AddComponent(); HapticProcessObservableList hapticList = listContainer.AddComponent(); hapticProcessor.HapticProcesses = hapticList; break; case OptionType.MeshStateModifier: MeshStateModifier meshStateModifier = componentContainer.AddComponent(); GameObjectMultiRelationObservableList gameObjectMultiRelationList = listContainer.AddComponent(); meshStateModifier.MeshCollections = gameObjectMultiRelationList; break; case OptionType.MomentProcessor: MomentProcessor momentProcessor = componentContainer.AddComponent(); MomentProcessObservableList momentProcessorList = listContainer.AddComponent(); momentProcessor.Processes = momentProcessorList; break; case OptionType.CompositeProcess: CompositeProcess compositeProcessor = componentContainer.AddComponent(); MomentProcessObservableList compositeProcessorList = listContainer.AddComponent(); compositeProcessor.Processes = compositeProcessorList; break; case OptionType.VelocityTrackerProcessor: VelocityTrackerProcessor velocityTrackerProcessor = componentContainer.AddComponent(); VelocityTrackerObservableList velocityTrackerList = listContainer.AddComponent(); velocityTrackerProcessor.VelocityTrackers = velocityTrackerList; break; case OptionType.FloatAdder: FloatAdder floatAdder = componentContainer.AddComponent(); FloatObservableList floatList = listContainer.AddComponent(); floatAdder.Collection = floatList; break; case OptionType.FloatMaxFinder: FloatMaxFinder floatMaxFinder = componentContainer.AddComponent(); FloatObservableList floatMaxFinderList = listContainer.AddComponent(); floatMaxFinder.Collection = floatMaxFinderList; break; case OptionType.FloatMeanFinder: FloatMeanFinder floatMeanFinder = componentContainer.AddComponent(); FloatObservableList floatMeanFinderList = listContainer.AddComponent(); floatMeanFinder.Collection = floatMeanFinderList; break; case OptionType.FloatMedianFinder: FloatMedianFinder floatMedianFinder = componentContainer.AddComponent(); FloatObservableList floatMedianFinderList = listContainer.AddComponent(); floatMedianFinder.Collection = floatMedianFinderList; break; case OptionType.FloatMinFinder: FloatMinFinder floatMinFinder = componentContainer.AddComponent(); FloatObservableList floatMinFinderList = listContainer.AddComponent(); floatMinFinder.Collection = floatMinFinderList; break; case OptionType.FloatModeFinder: FloatModeFinder floatModeFinder = componentContainer.AddComponent(); FloatObservableList floatModeFinderList = listContainer.AddComponent(); floatModeFinder.Collection = floatModeFinderList; break; case OptionType.FloatMultiplier: FloatMultiplier floatMultiplier = componentContainer.AddComponent(); FloatObservableList floatMultiplierList = listContainer.AddComponent(); floatMultiplier.Collection = floatMultiplierList; break; case OptionType.FloatRangeFinder: FloatRangeFinder floatRangeFinder = componentContainer.AddComponent(); FloatObservableList floatRangeFinderList = listContainer.AddComponent(); floatRangeFinder.Collection = floatRangeFinderList; break; case OptionType.FloatSubtractor: FloatSubtractor floatSubtractor = componentContainer.AddComponent(); FloatObservableList floatSubtractorList = listContainer.AddComponent(); floatSubtractor.Collection = floatSubtractorList; break; case OptionType.Vector2Adder: Vector2Adder vector2Adder = componentContainer.AddComponent(); Vector2ObservableList vector2AdderList = listContainer.AddComponent(); vector2Adder.Collection = vector2AdderList; break; case OptionType.Vector2Multiplier: Vector2Multiplier vector2Multiplier = componentContainer.AddComponent(); Vector2ObservableList vector2MultiplierList = listContainer.AddComponent(); vector2Multiplier.Collection = vector2MultiplierList; break; case OptionType.Vector2Subtractor: Vector2Subtractor vector2Subtractor = componentContainer.AddComponent(); Vector2ObservableList vector2SubtractorList = listContainer.AddComponent(); vector2Subtractor.Collection = vector2SubtractorList; break; case OptionType.Vector3Adder: Vector3Adder vector3Adder = componentContainer.AddComponent(); Vector3ObservableList vector3AdderList = listContainer.AddComponent(); vector3Adder.Collection = vector3AdderList; break; case OptionType.Vector3Multiplier: Vector3Multiplier vector3Multiplier = componentContainer.AddComponent(); Vector3ObservableList vector3MultiplierList = listContainer.AddComponent(); vector3Multiplier.Collection = vector3MultiplierList; break; case OptionType.Vector3Subtractor: Vector3Subtractor vector3Subtractor = componentContainer.AddComponent(); Vector3ObservableList vector3SubtractorList = listContainer.AddComponent(); vector3Subtractor.Collection = vector3SubtractorList; break; } } [MenuItem("Window/Zinnia/" + windowTitle)] private static void ShowWindow() { promptWindow = GetWindow(typeof(ObservableListComponentGeneratorEditorWindow)); promptWindow.titleContent = new GUIContent(windowTitle); } } }