void OnContentFieldChange(ChangeEvent <Object> evt) { if (evt == null) { return; } if (evt.previousValue == null) { var newObject = (Transform)evt.newValue; var isPrefab = PrefabUtility.IsPartOfPrefabAsset(newObject); if (isPrefab) { newObject = Object.Instantiate(newObject.gameObject).transform; } newObject.parent = BackingObject.transform; newObject.localPosition = Vector3.zero; } else { GameObject newObject = null; if (evt.newValue != null) { newObject = ((Transform)evt.newValue).gameObject; } RulesModule.ReplaceGameObject(newObject, (Transform)evt.previousValue, false); } }
protected override void Draw() { MarsObjectCreationPanel.DrawSection( MarsObjectCreationSettings.instance.ObjectCreationButtonSections[0], false, go => { RulesModule.ReplaceGameObject(go, m_Entity.transform); editorWindow.Close(); }); if (!(m_Entity is Proxy proxy)) { return; } GUILayout.Space(12); // Nested groups are not currently supported if (m_Entity && m_Entity.GetComponentInParent <ProxyGroup>()) { return; } const int buttonHeight = 24; if (GUILayout.Button("Convert to Group", GUILayout.Height(buttonHeight))) { RulesModule.ConvertProxyToGroup(proxy); editorWindow.Close(); } }
void SelectSimulatedReplicatorChildren() { var replicatorRow = (ReplicatorRow)this; var sceneObject = replicatorRow.BackingReplicator.transform; var simulatedObject = replicatorRow.SimulatedReplicator.transform; var simulatedMatches = CollectionPool <List <GameObject>, GameObject> .GetCollection(); foreach (var proxy in simulatedObject.GetComponentsInChildren <Proxy>()) { foreach (Transform child in proxy.transform) { if (child.gameObject.activeInHierarchy) { simulatedMatches.Add(child.gameObject); } } } RulesModule.FrameObject(sceneObject); // ReSharper disable once CoVariantArrayConversion Selection.objects = simulatedMatches.ToArray(); CollectionPool <List <GameObject>, GameObject> .RecycleCollection(simulatedMatches); }
internal static void OnGUI() { RulesModule.ReParentNewObject(); // Picker must be invoked from OnGUI for Event.current.commandName to be valid RulesModule.HandlePicker(); HandleInput(); }
static void AddRuleButton() { RulesModule.DoAddRule(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddRuleButtonAnalyticsLabel }); }
protected override void OnAddButton() { RulesModule.AddAction(m_Transform); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddButtonContentAnalyticsLabel }); }
protected override void OnAddButton() { RulesModule.AddContent(m_Entity.transform); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddButtonReplicatorAnalyticsLabel }); }
static void SetupUI() { var windowXml = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_WindowXMLPath); windowXml.CloneTree(s_RootVisualElement); s_AddRuleButton = s_RootVisualElement.Q <Button>(k_AddRuleName); s_AddRuleButton.clicked += AddRuleButton; s_AddRuleButton.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject); var windowStyle = AssetDatabase.LoadAssetAtPath <StyleSheet>(k_WindowStylePath); s_RootVisualElement.styleSheets.Add(windowStyle); s_RootVisualElement.AddToClassList(k_RootClassName); s_RootVisualElement.AddToClassList(EditorGUIUtility.isProSkin ? k_DarkModeClassName : k_LightModeClassName); s_RulesContainer = s_RootVisualElement.Q <VisualElement>(k_RulesAreaName); var sessionButton = s_RootVisualElement.Q <Button>(k_SessionButtonName); sessionButton.clicked += () => RulesModule.SetSelectedComponent(MARSSession.Instance); s_RootVisualElement.Q <Button>(k_RebuildButtonName).clicked += () => { s_RootVisualElement.Clear(); SetupUI(); }; s_DrillUpButton = s_RootVisualElement.Q <Button>(k_DrillUpButtonName); s_DrillUpButton.clicked += () => { RulesModule.RuleSetInstance = RulesModule.ParentRuleSet; BuildReplicatorsList(); }; s_GroupSettingsButton = s_RootVisualElement.Q <Button>(k_GroupSettingsButtonName); s_GroupSettingsButton.clicked += () => { var group = RulesModule.RuleSetInstance.GetComponent <ProxyGroup>(); Selection.activeGameObject = group.gameObject; group.transform.hideFlags = HideFlags.HideInInspector; EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_GroupSettingsButtonAnalyticsLabel }); }; BuildReplicatorsList(); }
static void UpdateGroupButtons() { RulesModule.CollectRuleSceneObjects(); s_DrillUpButton.SetEnabled(RulesModule.ParentRuleSet != null); s_GroupSettingsButton.SetEnabled(RulesModule.RuleSetInstanceExisting != null && RulesModule.RuleSetInstanceExisting.GetComponent <ProxyGroup>()); s_AddRuleButton.style.display = RulesModule.ParentRuleSet == null ? DisplayStyle.Flex : DisplayStyle.None; }
void OnChangeProxy(ChangeEvent <Object> evt) { // Container would be null if the replicator/row was deleted, which invokes this OnChange event. if (ContainerObject == null) { return; } var newProxy = (Proxy)evt.newValue; // Having no value in the Proxy is a malformed state, because Replicators can't exist without a Proxy child, // and a ReplicatorRow represents the Replicator+Proxy combo. Therefore, if the user clears out the Proxy field // (select the object field and hit 'delete'), we insert a new blank Proxy. if (newProxy == null) { MarsObjectCreationResources.instance.ProxyObjectPreset.CreateGameObject( out var createdGameObject, ContainerObject); if (createdGameObject != null) { createdGameObject.name = k_ReplacementProxyName; newProxy = createdGameObject.GetComponent <Proxy>(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_ReplaceDeletedProxyAnalyticsLabel }); } else { Debug.LogError("Attempted to set no Proxy for this rule, and was unable to generate a new blank Proxy. " + "This could happen because the MarsObjectCreationResources asset is misconfigured."); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_UnableToReplaceDeletedProxyErrorAnalyticsLabel }); return; } } RulesModule.ReplaceGameObject(newProxy.gameObject, ((Proxy)evt.previousValue).transform); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_ChangeProxyFieldAnalyticsEvent }); }
static void HandleInput() { var evt = Event.current; if (evt.type != EventType.KeyDown) { return; } if (evt.keyCode == KeyCode.Delete || evt.keyCode == KeyCode.Backspace) { RulesModule.DeleteSelectedRuleNode(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_DeleteKeyAnalyticsLabel }); } else if (evt.keyCode == KeyCode.Space) { var targetNode = RuleNode.HoveredAddBarNode ?? RuleNode.SelectedNode; RulesModule.AddNode(targetNode); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddKeyAnalyticsLabel }); } else if (evt.keyCode == KeyCode.UpArrow) { RuleNode.SelectPrevious(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectPreviousAnalyticsLabel }); } else if (evt.keyCode == KeyCode.DownArrow) { RuleNode.SelectNext(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectNextAnalyticsLabel }); } }
public override void OnInspectorGUI() { using (new GUILayout.HorizontalScope()) { if (GUILayout.Button(k_OpenAsWindowButtonText)) { RulesModule.RuleSetInstance = (ProxyRuleSet)target; RulesWindow.Init(); } var rules = (ProxyRuleSet)target; var visible = RulesModule.AllChildrenVisible(rules.transform); if (GUILayout.Button(visible ? m_HideContent : m_ShowContent)) { RulesModule.SetChildrenVisible(!visible, rules.transform); } } }
protected void Select(UnityObject obj, Transform viewObject, GameObject selectedRuleNode) { SelectedNode = this; if (obj.GetType() == typeof(Transform)) { Selection.activeTransform = (Transform)obj; } else { RulesModule.SetSelectedComponent(obj); } RulesModule.DisplayElementSelected(m_NodeContainer); RulesModule.SelectedRuleNode = selectedRuleNode; RulesModule.FrameObject(viewObject); EditorGUIUtility.PingObject(obj); }
protected void SetupProxyPresetUI(MARSEntity entity) { m_ProxyField = this.Q <ObjectField>(k_ProxyPresetName); m_ProxyField.objectType = typeof(Proxy); m_ProxyField.RegisterValueChangedCallback(OnChangeProxy); m_ProxyField.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject); var selector = m_ProxyField.Q <VisualElement>(className: ObjectField.selectorUssClassName); selector.style.display = DisplayStyle.None; m_PickProxyPresetButton = this.Q <Button>(k_PickProxyPresetName); m_PickProxyPresetButton.clicked += () => { var mouse = Event.current.mousePosition; RulesModule.DoPickProxyPresetButton(entity, new Rect(mouse.x, mouse.y, 0, 0)); }; m_PickProxyPresetButton.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject); }
void SetupSpawnContent() { m_ContentObjectField.objectType = typeof(Transform); m_ContentObjectField.RegisterValueChangedCallback(OnContentFieldChange); var content = m_Transform; var isLandmark = RulesModule.GetMarsObjectType(m_Transform) == MarsObjectType.Landmark; if (isLandmark) { content = content.childCount > 0 ? content.GetChild(0) : null; } if (content != null) { var so = new SerializedObject(content); so.Update(); m_NodeContainer.Bind(so); m_ContentObjectField.value = content; } var landmarkButton = this.Q <Button>(k_LandmarkButtonName); landmarkButton.clicked += () => { RulesModule.DoAddLandmark(m_ContainerTransform, m_Transform, () => { EditorApplication.delayCall += RulesDrawer.BuildReplicatorsList; }); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddLandmarkButtonAnalyticsLabel }); }; if (isLandmark) { landmarkButton.text = RulesModule.GetLandmarkName(m_Transform); } }
static void OnKeyDown(KeyDownEvent evt) { if (evt.keyCode == KeyCode.Delete || evt.keyCode == KeyCode.Backspace) { RulesModule.DeleteSelectedRuleNode(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_DeleteKeyAnalyticsLabel }); } else if (evt.keyCode == KeyCode.Space) { RulesModule.AddNode(SelectedNode); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddKeyAnalyticsLabel }); } else if (evt.keyCode == KeyCode.UpArrow) { SelectPrevious(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectPreviousAnalyticsLabel }); } else if (evt.keyCode == KeyCode.DownArrow) { SelectNext(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectNextAnalyticsLabel }); } }
void SelectSimulatedGroupChildren() { var simulatedObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>(); var sceneObject = ((ProxyRow)this).BackingObject.transform; var simulatedProxy = simulatedObjectsManager.GetCopiedTransform(sceneObject); var group = sceneObject.GetComponentInParent <ProxyGroup>(); var sceneProxy = sceneObject.GetComponent <Proxy>(); group.RepopulateChildList(); var idx = group.IndexOfChild(sceneProxy); var simulatedMatches = CollectionPool <List <GameObject>, GameObject> .GetCollection(); var parentReplicator = simulatedProxy.GetComponentInParent <Replicator>(); foreach (var simGrp in parentReplicator.GetComponentsInChildren <ProxyGroup>()) { var groupChildren = CollectionPool <List <Proxy>, Proxy> .GetCollection(); simGrp.GetChildList(groupChildren); foreach (Transform child in groupChildren[idx].transform) { if (child.gameObject.activeInHierarchy) { simulatedMatches.Add(child.gameObject); } } CollectionPool <List <Proxy>, Proxy> .RecycleCollection(groupChildren); } RulesModule.FrameObject(sceneObject); // ReSharper disable once CoVariantArrayConversion Selection.objects = simulatedMatches.ToArray(); CollectionPool <List <GameObject>, GameObject> .RecycleCollection(simulatedMatches); }
protected override AdvancedDropdownItem BuildRoot() { var root = new AdvancedDropdownItem(k_ProxyActionsLabel); root.AddChild(new ActionsDropdownItem(k_SpawnObjectLabel, () => { RulesModule.Pick <GameObject>(obj => { if (obj == null) { return; } var go = UnityObject.Instantiate(obj); Undo.RegisterCreatedObjectUndo(go, $"Add content: {go.name}"); RulesModule.NewObject = go.transform; }); })); root.AddChild(new ActionsDropdownItem(k_MaterialLabel, () => { RulesModule.Pick <Material>(mat => { if (mat == null) { return; } var buildSurfaceObject = RulesModule.CreateBuildSurfaceObject(mat); RulesModule.NewObject = buildSurfaceObject.transform; }); })); return(root); }
void DisplayContextMenu(Vector2 mousePosition) { var menu = new GenericMenu(); var backingTransform = BackingObject.transform; if (this is ReplicatorRow || this is ProxyRow || this is ContentRow) { Transform proxyTransform = null; switch (this) { case ReplicatorRow _: menu.AddItem(Styles.AddNewRuleContent, false, () => { RulesModule.DoAddRule(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddRuleAnalyticsLabel }); }); proxyTransform = ((ReplicatorRow)this).Entity.transform; break; case ProxyRow _: proxyTransform = ((ProxyRow)this).ContainerObject; break; case ContentRow _: { var container = ((ContentRow)this).ContainerObject; var proxy = container.GetComponent <Proxy>(); if (proxy != null) { proxyTransform = proxy.transform; } else { proxy = container.GetComponentInParent <Proxy>(); if (proxy != null) { proxyTransform = proxy.transform; } else { Debug.LogErrorFormat(BackingObject, Styles.NoProxyFormat, name); return; } } break; } } if (proxyTransform == null) { Debug.LogError("Could not find Proxy"); return; } menu.AddItem(new GUIContent(string.Format(Styles.AddContentFormat, proxyTransform.name)), false, () => { EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddContentToProxyAnalyticsLabel }); RulesModule.AddContent(proxyTransform, mousePosition); }); if (this is ReplicatorRow || this is ProxyRow) { menu.AddSeparator(string.Empty); var simulatedObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>(); if (simulatedObjectsManager == null) { menu.AddDisabledItem(Styles.SelectSimulatedObjectsContent); } else { if (this is ReplicatorRow) { var replicatorRow = (ReplicatorRow)this; if (replicatorRow.SimulatedReplicator == null) { menu.AddDisabledItem(Styles.SelectSimulatedObjectsContent); } else { menu.AddItem(Styles.SelectSimulatedObjectsContent, false, () => { SelectSimulatedReplicatorChildren(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectSimulatedObjectsAnalyticsLabel }); }); } } else if (this is ProxyRow) { var sceneObject = ((ProxyRow)this).BackingObject.transform; var simulatedProxy = simulatedObjectsManager.GetCopiedTransform(sceneObject); if (simulatedProxy == null) { menu.AddDisabledItem(Styles.SelectSimulatedObjectsContent); } else { menu.AddItem(Styles.SelectSimulatedObjectsContent, false, () => { SelectSimulatedGroupChildren(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_SelectSimulatedGroupAnalyticsLabel }); }); } } } } } if (this is ContentRow || this is ActionRow) { var contentTransform = this is ContentRow ? BackingObject.transform : ContainerObject; var contentName = contentTransform.name; var contentSupportsActions = true; if (this is ContentRow) { if (!((ContentRow)this).ContentSupportsActions) { contentSupportsActions = false; } } if (contentSupportsActions) { menu.AddItem(new GUIContent(string.Format(Styles.AddActionFormat, contentName)), false, () => { RulesModule.AddAction(contentTransform, mousePosition); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddActionToContentButtonAnalyticsLabel }); }); } } menu.AddSeparator(string.Empty); var siblingIndex = backingTransform.GetSiblingIndex(); if (siblingIndex > 0) { menu.AddItem(Styles.MoveUpContent, false, () => { backingTransform.SetSiblingIndex(siblingIndex - 1); RulesDrawer.BuildReplicatorsList(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_MoveUpAnalyticsLabel }); }); } else { menu.AddDisabledItem(Styles.MoveUpContent); } var backingParent = backingTransform.parent; if (backingParent == null || siblingIndex == backingParent.childCount - 1) { menu.AddDisabledItem(Styles.MoveDownContent); } else { menu.AddItem(Styles.MoveDownContent, false, () => { backingTransform.SetSiblingIndex(siblingIndex + 1); RulesDrawer.BuildReplicatorsList(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_MoveDownAnalyticsLabel }); }); } menu.AddItem(Styles.DeleteContent, false, () => { Undo.DestroyObjectImmediate(BackingObject); RulesDrawer.BuildReplicatorsList(); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_DeleteAnalyticsLabel }); }); menu.ShowAsContext(); }