protected override void OnAddButton() { RulesModule.AddAction(m_Transform); EditorEvents.RulesUiUsed.Send(new RuleUiArgs { label = k_AddButtonContentAnalyticsLabel }); }
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(); }