Beispiel #1
0
        /// <summary>
        /// Triggered when the user selects a new resource or a scene object, or deselects everything.
        /// </summary>
        /// <param name="objects">A set of new scene objects that were selected.</param>
        /// <param name="paths">A set of absolute resource paths that were selected.</param>
        private void OnSelectionChanged(SceneObject[] objects, string[] paths)
        {
            if (currentType == InspectorType.SceneObject && modifyState == InspectableState.NotModified)
            {
                UndoRedo.Global.PopCommand(undoCommandIdx);
            }

            Clear();
            modifyState = InspectableState.NotModified;

            if (objects.Length == 0 && paths.Length == 0)
            {
                currentType         = InspectorType.None;
                inspectorScrollArea = new GUIScrollArea();
                GUI.AddElement(inspectorScrollArea);
                inspectorLayout = inspectorScrollArea.Layout;

                inspectorLayout.AddFlexibleSpace();
                GUILayoutX layoutMsg = inspectorLayout.AddLayoutX();
                layoutMsg.AddFlexibleSpace();
                layoutMsg.AddElement(new GUILabel(new LocEdString("No object selected")));
                layoutMsg.AddFlexibleSpace();
                inspectorLayout.AddFlexibleSpace();
            }
            else if ((objects.Length + paths.Length) > 1)
            {
                currentType         = InspectorType.None;
                inspectorScrollArea = new GUIScrollArea();
                GUI.AddElement(inspectorScrollArea);
                inspectorLayout = inspectorScrollArea.Layout;

                inspectorLayout.AddFlexibleSpace();
                GUILayoutX layoutMsg = inspectorLayout.AddLayoutX();
                layoutMsg.AddFlexibleSpace();
                layoutMsg.AddElement(new GUILabel(new LocEdString("Multiple objects selected")));
                layoutMsg.AddFlexibleSpace();
                inspectorLayout.AddFlexibleSpace();
            }
            else if (objects.Length == 1)
            {
                if (objects[0] != null)
                {
                    UndoRedo.RecordSO(objects[0]);
                    undoCommandIdx = UndoRedo.Global.TopCommandId;

                    SetObjectToInspect(objects[0]);
                }
            }
            else if (paths.Length == 1)
            {
                SetObjectToInspect(paths[0]);
            }
        }
Beispiel #2
0
        private static void AddBone()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                return;
            }

            UndoRedo.RecordSO(so, false, "Added an Bone component");
            so.AddComponent <Bone>();
            EditorApplication.SetSceneDirty();
        }
Beispiel #3
0
        private static void RevertToPrefab()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                return;
            }

            UndoRedo.RecordSO(so, true, "Reverting \"" + so.Name + "\" to prefab.");

            PrefabUtility.RevertPrefab(so);
            EditorApplication.SetSceneDirty();
        }
Beispiel #4
0
        private static void AddDirectionalLight()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                return;
            }

            UndoRedo.RecordSO(so, false, "Added a Light component");
            Light light = so.AddComponent <Light>();

            light.Type = LightType.Directional;
            EditorApplication.SetSceneDirty();
        }
Beispiel #5
0
        private static void AddAudioSource()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                so = UndoRedo.CreateSO("AudioSource", "New scene object");

                Selection.SceneObject = so;
                FocusOnHierarchyOrScene();
            }

            UndoRedo.RecordSO(so, false, "Added a AudioSource component");
            so.AddComponent <AudioSource>();
            EditorApplication.SetSceneDirty();
        }
Beispiel #6
0
        private static void AddSliderJoint()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                so = UndoRedo.CreateSO("SliderJoint", "New scene object");

                Selection.SceneObject = so;
                FocusOnHierarchyOrScene();
            }

            UndoRedo.RecordSO(so, false, "Added a SliderJoint component");
            so.AddComponent <SliderJoint>();
            EditorApplication.SetSceneDirty();
        }
Beispiel #7
0
        private static void AddCharacterController()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                so = UndoRedo.CreateSO("CharacterController", "New scene object");

                Selection.SceneObject = so;
                FocusOnHierarchyOrScene();
            }

            UndoRedo.RecordSO(so, false, "Added a CharacterController component");
            so.AddComponent <CharacterController>();
            EditorApplication.SetSceneDirty();
        }
Beispiel #8
0
        private static void AddCamera()
        {
            SceneObject so = Selection.SceneObject;

            if (so == null)
            {
                return;
            }

            UndoRedo.RecordSO(so, false, "Added a Camera component");
            Camera cam = so.AddComponent <Camera>();

            cam.Main = true;

            EditorApplication.SetSceneDirty();
        }
Beispiel #9
0
        /// <summary>
        /// Updates contents of the scene object specific fields (name, position, rotation, etc.)
        /// </summary>
        /// <param name="forceUpdate">If true, the GUI elements will be updated regardless of whether a change was
        ///                           detected or not.</param>
        private void RefreshSceneObjectFields(bool forceUpdate)
        {
            if (activeSO == null)
            {
                return;
            }

            soNameInput.Text     = activeSO.Name;
            soActiveToggle.Value = activeSO.Active;
            soMobility.Value     = (ulong)activeSO.Mobility;

            SceneObject prefabParent = PrefabUtility.GetPrefabParent(activeSO);

            // Ignore prefab parent if scene root, we only care for non-root prefab instances
            bool hasPrefab = prefabParent != null && prefabParent.Parent != null;

            if (soHasPrefab != hasPrefab || forceUpdate)
            {
                int numChildren = soPrefabLayout.ChildCount;
                for (int i = 0; i < numChildren; i++)
                {
                    soPrefabLayout.GetChild(0).Destroy();
                }

                GUILabel prefabLabel = new GUILabel(new LocEdString("Prefab"), GUIOption.FixedWidth(50));
                soPrefabLayout.AddElement(prefabLabel);

                if (hasPrefab)
                {
                    GUIButton btnApplyPrefab  = new GUIButton(new LocEdString("Apply"), GUIOption.FixedWidth(60));
                    GUIButton btnRevertPrefab = new GUIButton(new LocEdString("Revert"), GUIOption.FixedWidth(60));
                    GUIButton btnBreakPrefab  = new GUIButton(new LocEdString("Break"), GUIOption.FixedWidth(60));

                    btnApplyPrefab.OnClick += () =>
                    {
                        PrefabUtility.ApplyPrefab(activeSO);
                    };
                    btnRevertPrefab.OnClick += () =>
                    {
                        UndoRedo.RecordSO(activeSO, true, "Reverting \"" + activeSO.Name + "\" to prefab.");

                        PrefabUtility.RevertPrefab(activeSO);
                        EditorApplication.SetSceneDirty();
                    };
                    btnBreakPrefab.OnClick += () =>
                    {
                        UndoRedo.BreakPrefab(activeSO, "Breaking prefab link for " + activeSO.Name);

                        EditorApplication.SetSceneDirty();
                    };

                    soPrefabLayout.AddElement(btnApplyPrefab);
                    soPrefabLayout.AddElement(btnRevertPrefab);
                    soPrefabLayout.AddElement(btnBreakPrefab);
                }
                else
                {
                    GUILabel noPrefabLabel = new GUILabel("None");
                    soPrefabLayout.AddElement(noPrefabLabel);
                }

                soHasPrefab = hasPrefab;
            }

            Vector3 position;
            Vector3 angles;

            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
            {
                position = activeSO.Position;
                angles   = activeSO.Rotation.ToEuler();
            }
            else
            {
                position = activeSO.LocalPosition;
                angles   = activeSO.LocalRotation.ToEuler();
            }

            Vector3 scale = activeSO.LocalScale;

            if (!soPosX.HasInputFocus)
            {
                soPosX.Value = position.x;
            }

            if (!soPosY.HasInputFocus)
            {
                soPosY.Value = position.y;
            }

            if (!soPosZ.HasInputFocus)
            {
                soPosZ.Value = position.z;
            }

            if (!soRotX.HasInputFocus)
            {
                soRotX.Value = angles.x;
            }

            if (!soRotY.HasInputFocus)
            {
                soRotY.Value = angles.y;
            }

            if (!soRotZ.HasInputFocus)
            {
                soRotZ.Value = angles.z;
            }

            if (!soScaleX.HasInputFocus)
            {
                soScaleX.Value = scale.x;
            }

            if (!soScaleY.HasInputFocus)
            {
                soScaleY.Value = scale.y;
            }

            if (!soScaleZ.HasInputFocus)
            {
                soScaleZ.Value = scale.z;
            }
        }
        /// <summary>
        /// Updates contents of the scene object specific fields (name, position, rotation, etc.)
        /// </summary>
        /// <param name="forceUpdate">If true, the GUI elements will be updated regardless of whether a change was
        ///                           detected or not.</param>
        private void RefreshSceneObjectFields(bool forceUpdate)
        {
            if (activeSO == null)
            {
                return;
            }

            soNameInput.Text     = activeSO.Name;
            soActiveToggle.Value = activeSO.Active;
            soMobility.Value     = (ulong)activeSO.Mobility;

            SceneObject prefabParent = PrefabUtility.GetPrefabParent(activeSO);

            // Ignore prefab parent if scene root, we only care for non-root prefab instances
            bool hasPrefab = prefabParent != null && prefabParent.Parent != null;

            if (soHasPrefab != hasPrefab || forceUpdate)
            {
                int numChildren = soPrefabLayout.ChildCount;
                for (int i = 0; i < numChildren; i++)
                {
                    soPrefabLayout.GetChild(0).Destroy();
                }

                GUILabel prefabLabel = new GUILabel(new LocEdString("Prefab"), GUIOption.FixedWidth(50));
                soPrefabLayout.AddElement(prefabLabel);

                if (hasPrefab)
                {
                    GUIButton btnApplyPrefab  = new GUIButton(new LocEdString("Apply"), GUIOption.FixedWidth(60));
                    GUIButton btnRevertPrefab = new GUIButton(new LocEdString("Revert"), GUIOption.FixedWidth(60));
                    GUIButton btnBreakPrefab  = new GUIButton(new LocEdString("Break"), GUIOption.FixedWidth(60));

                    btnApplyPrefab.OnClick += () =>
                    {
                        PrefabUtility.ApplyPrefab(activeSO);
                    };
                    btnRevertPrefab.OnClick += () =>
                    {
                        UndoRedo.RecordSO(activeSO, true, "Reverting \"" + activeSO.Name + "\" to prefab.");

                        PrefabUtility.RevertPrefab(activeSO);
                        EditorApplication.SetSceneDirty();
                    };
                    btnBreakPrefab.OnClick += () =>
                    {
                        UndoRedo.BreakPrefab(activeSO, "Breaking prefab link for " + activeSO.Name);

                        EditorApplication.SetSceneDirty();
                    };

                    soPrefabLayout.AddElement(btnApplyPrefab);
                    soPrefabLayout.AddElement(btnRevertPrefab);
                    soPrefabLayout.AddElement(btnBreakPrefab);
                }
                else
                {
                    GUILabel noPrefabLabel = new GUILabel("None");
                    soPrefabLayout.AddElement(noPrefabLabel);
                }

                soHasPrefab = hasPrefab;
            }

            Vector3    position;
            Quaternion rotation;

            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
            {
                position = activeSO.Position;
                rotation = activeSO.Rotation;
            }
            else
            {
                position = activeSO.LocalPosition;
                rotation = activeSO.LocalRotation;
            }

            Vector3 scale = activeSO.LocalScale;

            if (!soPos.HasInputFocus)
            {
                soPos.Value = position;
            }

            // Avoid updating the rotation unless actually changed externally, since switching back and forth between
            // quaternion and euler angles can cause weird behavior
            if (!soRot.HasInputFocus && rotation != lastRotation)
            {
                soRot.Value  = rotation.ToEuler();
                lastRotation = rotation;
            }

            if (!soScale.HasInputFocus)
            {
                soScale.Value = scale;
            }
        }