コード例 #1
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;
            }
        }