internal static void ConvertProxyToGroup(Proxy proxy)
        {
            var proxyTransform = proxy.transform;
            // RuleSet added to group object because the RuleSet drawer only draws for RuleSet objects
            var group =
                new GameObject("New Group", typeof(ProxyRuleSet))
                .AddComponent <ProxyGroup>();
            var groupTransform = group.transform;

            groupTransform.parent   = proxyTransform.parent;
            groupTransform.position = proxyTransform.position;
            proxyTransform.parent   = groupTransform;

            var newProxy = new GameObject("Surface", typeof(IsPlaneCondition)).AddComponent <Proxy>();

            newProxy.gameObject.AddComponent <SetPoseAction>();
            newProxy.gameObject.AddComponent <ShowChildrenOnTrackingAction>();

            var newProxyTransform = newProxy.transform;

            newProxyTransform.parent        = groupTransform;
            newProxyTransform.localPosition = Vector3.right * k_GroupObjectSceneOffset;

            RulesDrawer.BuildReplicatorsList();

            EditorEvents.RulesUiUsed.Send(new RuleUiArgs
            {
                label = k_ConvertToGroupAnalyticsLabel
            });
        }
示例#2
0
        internal override void Select()
        {
            if (m_Entity == null)
            {
                Debug.LogWarning("MARSEntity missing; rebuilding list.");
                RulesDrawer.BuildReplicatorsList();
                return;
            }

            base.Select(m_Entity, m_Entity.transform, BackingReplicator.gameObject);

            m_Foldout.value = true;
        }
        internal static void DeleteSelectedRuleNode()
        {
            if (SelectedRuleNode == null)
            {
                return;
            }

            if (ParentRuleSet != null) // Don't allow deletion within a group.
            {
                return;
            }

            Undo.DestroyObjectImmediate(SelectedRuleNode);
            RulesDrawer.BuildReplicatorsList();
        }
示例#4
0
        void OnEnable()
        {
            minSize = k_MinSize;

            if (m_SerializedActiveRuleSet != null)
            {
                RulesModule.RuleSetInstance = m_SerializedActiveRuleSet;
            }

            RulesDrawer.Init(rootVisualElement);

            EditorEvents.WindowUsed.Send(new UiComponentArgs {
                label = k_RulesWindowName, active = true
            });
        }
        internal static void ReplaceGameObject(GameObject replacement, Transform currentTransform,
                                               bool reParentChildren = true)
        {
            // `replacement` would be null when the user has selected 'None' from the object picker.
            // A content row represents a Transform, so setting a row to 'None' is undefined.
            // Deleting the row in this situation is the wrong move, because it would feel like broken behavior,
            // and would prevent the workflow of removing an object from the row without providing a replacement.
            // Therefore, we create an empty object.  This object has no effect and will be replaced when any other object
            // is assigned to the field via drag+drop or picker.
            if (replacement == null)
            {
                replacement = new GameObject(k_EmptyObjectName);
            }

            var isPrefab = PrefabUtility.IsPartOfPrefabAsset(replacement);

            var newTransform = replacement.transform;

            if (isPrefab)
            {
                newTransform = UnityObject.Instantiate(replacement).transform;
            }

            newTransform.parent        = currentTransform.parent;
            newTransform.localPosition = Vector3.zero;

            if (reParentChildren)
            {
                ReParentChildren(currentTransform, newTransform);
            }
            else
            {
                UnityObject.DestroyImmediate(currentTransform.gameObject);
            }

            var cloneIdx = newTransform.name.IndexOf("(Clone)", StringComparison.Ordinal);

            if (cloneIdx > -1)
            {
                newTransform.name =
                    newTransform.name.Substring(0, cloneIdx);
            }

            RulesDrawer.BuildReplicatorsList();
        }
示例#6
0
        void OnGUI()
        {
            if (!MARSEntitlements.instance.EntitlementsCheckGUI(position.width))
            {
                return;
            }

            if (Event.current.commandName == "ObjectSelectorClosed" && !RulesModule.WasPicked)
            {
                RulesModule.PickedObject = EditorGUIUtility.GetObjectPickerObject();
            }

            RulesDrawer.OnGUI();

            if (GUIDispatch != null)
            {
                GUIDispatch();
                GUIDispatch = null;
            }

            m_SerializedActiveRuleSet = RulesModule.RuleSetInstanceExisting;
        }
        static void OnSelectionChanged()
        {
            var go = Selection.activeGameObject;

            if (go == null)
            {
                return;
            }

            var ruleSet = go.GetComponent <ProxyRuleSet>();

            if (ruleSet != null)
            {
                RuleSetInstance = ruleSet;
                RulesDrawer.BuildReplicatorsList();
                return;
            }

            var entity = go.GetComponent <MARSEntity>();

            if (entity == null)
            {
                return;
            }

            var moduleLoaderCore        = ModuleLoaderCore.instance;
            var simulatedObjectsManager = moduleLoaderCore.GetModule <SimulatedObjectsManager>();
            var originalSimTransform    = simulatedObjectsManager.GetOriginalTransform(go.transform);

            if (originalSimTransform == null)
            {
                return;
            }

            FrameObject(originalSimTransform);
        }
        protected void CreateAddContentButton()
        {
            if (m_Entity is ProxyGroup)
            {
                var groupButton = new Button {
                    text = k_EditGroupContent
                };
                groupButton.style.width      = 160;
                groupButton.style.marginLeft = 30;
                groupButton.clicked         += () =>
                {
                    EditorEvents.RulesUiUsed.Send(new RuleUiArgs
                    {
                        label = k_EditGroupButtonAnalyticsLabel
                    });

                    var ruleset = m_Entity.GetComponent <ProxyRuleSet>();
                    Selection.activeGameObject  = m_Entity.gameObject;
                    RulesModule.RuleSetInstance = ruleset;
                    RulesDrawer.BuildReplicatorsList();
                };
                m_ContentContainer.Add(groupButton);
            }
        }
示例#9
0
        protected sealed override void SetupUI()
        {
            var replicatorRowAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_ReplicatorRowPath);

            replicatorRowAsset.CloneTree(this);

            base.SetupUI();

            m_ContentContainer = this.Q <VisualElement>(k_ContentContainerName);

            m_Foldout = this.Q <Foldout>(k_RowFoldoutName);
            m_Foldout.RegisterValueChangedCallback(evt =>
            {
                var expanded = evt.newValue;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
                if (expanded)
                {
                    RulesModule.CollapsedNodes.Remove(BackingObject);
                }
                else
                {
                    RulesModule.CollapsedNodes.Add(BackingObject);
                }

                RulesDrawer.BuildReplicatorsList();
            });

            m_Foldout.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            if (IsGroup)
            {
                m_Foldout.visible = false;
            }
            else
            {
                var expanded = !RulesModule.CollapsedNodes.Contains(BackingObject);
                m_Foldout.value = expanded;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
            }

            m_MatchCountEnum = this.Q <EnumField>(k_MatchCountEnum);
            m_MatchCountEnum.Init(RulesModule.ReplicatorCountOption.Every);
            m_MatchCountEnum.RegisterCallback <ChangeEvent <System.Enum> >(OnChangeMatchCountDropdown);

            m_MaxCountField = this.Q <IntegerField>(k_MaxInstancesName);
            m_MaxCountField.RegisterValueChangedCallback(OnMaxInstanceChanged);

            m_MaxCountField.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            SetupProxyPresetUI(m_Entity);

            m_GroupDrillInButton          = this.Q <Button>(k_GroupDrillIn);
            m_GroupDrillInButton.clicked += () =>
            {
                var ruleSet = m_Entity.GetComponent <ProxyRuleSet>();
                RulesModule.RuleSetInstance = ruleSet;
                RulesDrawer.BuildReplicatorsList();
            };

            if (!IsGroup)
            {
                m_GroupDrillInButton.style.display = DisplayStyle.None;
            }

            m_SimMatchCount = this.Q <Label>(k_SimMatchCountName);

            SetupReplicatorRow();

            if (IsGroup)
            {
                m_AddButtonHoverElement.SetEnabled(false);
            }

            CreateAddContentButton();

            RegisterCallback <KeyDownEvent>(OnKeyDown);
        }
 static void OnSceneChanged(Scene oldScene, Scene newScene)
 {
     RulesDrawer.BuildReplicatorsList();
 }
        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();
        }