Exemplo n.º 1
0
        static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            var obj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            if (hierarchyHelperObj == null)
            {
                hierarchyHelperObj = HierarchyHelper.Instance?.gameObject;
                if (hierarchyHelperObj == null)
                {
                    return;
                }
            }

            if (obj == hierarchyHelperObj)
            {
                return;
            }

            if (obj != null)
            {
                bool value = (obj.hideFlags & HideFlags.HideInHierarchy) == HideFlags.HideInHierarchy;

                Rect r = new Rect(selectionRect);

                r.x += r.width - 65;

                EditorGUI.BeginChangeCheck();

                var toggleValue = GUI.Toggle(r, value, "Hide");

                if (EditorGUI.EndChangeCheck())
                {
                    if (toggleValue)
                    {
                        obj.hideFlags |= HideFlags.HideInHierarchy;
                        HierarchyHelper.Instance.hiddenObjects.Add(obj);
                        Selection.activeObject = hierarchyHelperObj;
                        try
                        {
                            EditorApplication.DirtyHierarchyWindowSorting();
                        }
                        catch
                        {
                            // Ignore
                        }
                    }
                }
            }
        }
        internal static void SetChildrenVisible(bool visible, Transform instance)
        {
            using (var undoBlock = new UndoBlock("Setting visibility"))
            {
                foreach (Transform child in instance.transform)
                {
                    undoBlock.RecordObject(child);
                    child.gameObject.hideFlags = visible ? HideFlags.None : HideFlags.HideInHierarchy;
                }
            }

            EditorApplication.DirtyHierarchyWindowSorting(); // helps editor know to update

            s_LastSetChildrenVisible = visible;
        }
Exemplo n.º 3
0
 public void HideChildren()
 {
     Transform[] transforms = gameObject.GetComponentsInChildren <Transform>();
     for (int i = 0; i < transforms.Length; i++)
     {
         if (!hiddenChildren)
         {
             transforms[i].gameObject.hideFlags = HideFlags.None;
         }
         else if (transforms[i] != transform)
         {
             transforms[i].gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable | HideFlags.HideInInspector;
         }
     }
     EditorApplication.DirtyHierarchyWindowSorting();
 }
Exemplo n.º 4
0
        private static void Sort()
        {
            GameObject[] gameObjects = Selection.gameObjects;
            if (gameObjects.Length == 0)
            {
                return;
            }

            for (int i = 0; i < Selection.transforms.Length; i++)
            {
                Transform transform = Selection.transforms[i];
                Sort(transform);
            }

            EditorApplication.DirtyHierarchyWindowSorting();
        }
Exemplo n.º 5
0
 static void SetShowBricks(bool show, ICollection <Brick> bricks)
 {
     EditorPrefs.SetBool(showAllBricksPrefsKey, show);
     showAllBricks = show;
     foreach (var brick in bricks)
     {
         if (showAllBricks)
         {
             brick.transform.hideFlags &= ~HideFlags.HideInHierarchy;
         }
         else
         {
             brick.transform.hideFlags |= HideFlags.HideInHierarchy;
         }
     }
     EditorApplication.DirtyHierarchyWindowSorting();
 }
 public void ShowHideChildren()
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         if (hideChildren == false)
         {
             transform.GetChild(i).hideFlags = HideFlags.None;
         }
         else
         {
             transform.GetChild(i).hideFlags = HideFlags.HideInHierarchy;
         }
     }
     // Does not work!?
     // EditorApplication.RepaintHierarchyWindow();
     // But this works
     EditorApplication.DirtyHierarchyWindowSorting();
 }
Exemplo n.º 7
0
        internal static void Paste()
        {
            if (isIgnored)
            {
                SmartHierarchy.active.window.hierarchy.PasteGO();
                return;
            }

            if (Selection.transforms.Length == 0)
            {
                SmartHierarchy.active.window.hierarchy.PasteGO();
                return;
            }

            var targetSelection  = Selection.activeTransform;
            var isTargetExpanded = SmartHierarchy.active.controller.IsExpanded(Selection.activeInstanceID) &&
                                   Selection.activeTransform.childCount > 0;

            var alwaysPasteAsChild       = prefs.autoPasteAsChild == AutoPasteAsChild.Always;
            var pasteAsChildWhenExpanded = prefs.autoPasteAsChild == AutoPasteAsChild.OnExpandedSelection;


            var oldSelection = GetSiblingsPlace(Selection.transforms, out var siblingIndex);

            SmartHierarchy.active.window.hierarchy.PasteGO();

            var selectionChanged = !Selection.transforms.SequenceEqual(oldSelection);

            if (alwaysPasteAsChild || pasteAsChildWhenExpanded && isTargetExpanded)
            {
                foreach (var transform in Selection.transforms)
                {
                    transform.SetParent(targetSelection);
                }
                SetSiblingsInPlaceAndFrame(0, Selection.transforms);

                SmartHierarchy.active.ReloadView();
                EditorApplication.DirtyHierarchyWindowSorting();
            }
            else if (selectionChanged)
            {
                SetSiblingsInPlaceAndFrame(siblingIndex, Selection.transforms);
            }
        }
Exemplo n.º 8
0
 public static void ToggleInHierarchy(Object obj, bool visible)
 {
     #if UNITY_EDITOR
     if (visible)
     {
         obj.hideFlags = HideFlags.None;
     }
     else
     {
         obj.hideFlags = HideFlags.HideInHierarchy;
     }
     try
     {
         EditorApplication.RepaintHierarchyWindow();
         EditorApplication.DirtyHierarchyWindowSorting();
     }
     catch { }
     #endif
 }
Exemplo n.º 9
0
        //在这里方法中就可以绘制面板。
        public override void OnInspectorGUI()
        {
            curEntity = poolConfig.CurEntity;

            serializedObject.Update();
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Edit"))
            {
                ZEditorWindow.ShowEditor();
            }

            var oldColor = GUI.color;

            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("Entity x " + poolConfig.CurPool.TemplateCount);

            GUILayout.FlexibleSpace();

            GUI.color = oldColor;


            if (GUILayout.Button("Reload"))
            {
                Reload();
            }

            EditorGUILayout.EndHorizontal();

            if (curEntity != null)
            {
                DrawEntity();
            }
            else
            {
                EditorGUILayout.LabelField("please select a entity");
            }

            //serializedObject.Update();
            serializedObject.SetIsDifferentCacheDirty();
            EditorApplication.DirtyHierarchyWindowSorting();
            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 10
0
        internal void SetHideFlags(HideFlags hideFlags)
        {
            ObjectUtils.hideFlags = hideFlags;

            foreach (var manager in Resources.FindObjectsOfTypeAll <InputManager>())
            {
                manager.gameObject.hideFlags = hideFlags;
            }

            EditingContextManager.instance.gameObject.hideFlags = hideFlags;

            foreach (var child in GetComponentsInChildren <Transform>(true))
            {
                child.gameObject.hideFlags = hideFlags;
            }

#if UNITY_EDITOR
            EditorApplication.DirtyHierarchyWindowSorting(); // Otherwise objects aren't shown/hidden in hierarchy window
#endif
        }
Exemplo n.º 11
0
        private static void CreateEmpty()
        {
            Transform  activeTransform = Selection.activeTransform;
            GameObject go = new GameObject("GameObject");

            Undo.RegisterCreatedObjectUndo(go, "CreateEmpty");
            Selection.activeGameObject = go;
            if (activeTransform) // 移动到选择的物体上
            {
                go.transform.SetParent(activeTransform, false);
                go.transform.SetAsFirstSibling();
                EditorApplication.DirtyHierarchyWindowSorting();
                go.layer = activeTransform.gameObject.layer;

                RectTransform rtTransform = activeTransform.GetComponent <RectTransform>();
                if (rtTransform)
                {
                    go.AddComponent <RectTransform>();
                }
            }
        }
Exemplo n.º 12
0
        static void SetGameObjectVisibility(GameObject obj, bool visible)
        {
            if (obj != null)
            {
                obj.hideFlags = visible ? HideFlags.None : HideFlags.HideInHierarchy;

                if (!Application.isPlaying)
                {
                    try
                    {
                        EditorSceneManager.MarkSceneDirty(obj.scene);
                        EditorApplication.RepaintHierarchyWindow();
                        EditorApplication.DirtyHierarchyWindowSorting();
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void UpdateReflectionCamera(Camera realCamera)
        {
            if (_reflectionCamera == null)
            {
                _reflectionCamera = InitializeReflectionCamera();
            }

            Vector3 pos    = Vector3.zero;
            Vector3 normal = Vector3.up;

            if (reflectionTarget != null)
            {
                pos    = reflectionTarget.transform.position + Vector3.up * reflectionPlaneOffset;
                normal = reflectionTarget.transform.up;
            }

            UpdateCamera(realCamera, _reflectionCamera);
            _reflectionCamera.gameObject.hideFlags = (hideReflectionCamera) ? HideFlags.HideAndDontSave : HideFlags.DontSave;
            #if UNITY_EDITOR
            EditorApplication.DirtyHierarchyWindowSorting();
            #endif

            var d = -Vector3.Dot(normal, pos);
            var reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

            var reflection = Matrix4x4.identity;
            reflection *= Matrix4x4.Scale(new Vector3(1, -1, 1));

            PlanarReflections.CalculateReflectionMatrix(ref reflection, reflectionPlane);
            var oldPosition = realCamera.transform.position - new Vector3(0, pos.y * 2, 0);
            var newPosition = PlanarReflections.ReflectPosition(oldPosition);
            _reflectionCamera.transform.forward   = Vector3.Scale(realCamera.transform.forward, new Vector3(1, -1, 1));
            _reflectionCamera.worldToCameraMatrix = realCamera.worldToCameraMatrix * reflection;

            var clipPlane  = CameraSpacePlane(_reflectionCamera, pos - Vector3.up * 0.1f, normal, 1.0f);
            var projection = realCamera.CalculateObliqueMatrix(clipPlane);
            _reflectionCamera.projectionMatrix   = projection;
            _reflectionCamera.cullingMask        = reflectionLayer;
            _reflectionCamera.transform.position = newPosition;
        }
        //---------------------------------------------------------------------
        // Public
        //---------------------------------------------------------------------

        public static void UpdateSceneConfigVisibility(bool isVisible)
        {
            var configInstances = RainbowHierarchySceneConf.Instances;

            if (configInstances == null || configInstances.Count < 1)
            {
                return;
            }

            foreach (var rainbowHierarchySceneConf in configInstances)
            {
                if (rainbowHierarchySceneConf == null)
                {
                    return;
                }
                rainbowHierarchySceneConf.transform.hideFlags = isVisible
                    ? HideFlags.None
                    : HideFlags.HideInHierarchy;
            }

            EditorApplication.DirtyHierarchyWindowSorting();
        }
Exemplo n.º 15
0
        private void OnGUI()
        {
            var selection = Selection.activeGameObject;

            if (selection)
            {
                if ((selection.hideFlags & HideFlags.HideInHierarchy) != 0)
                {
                    if (GUILayout.Button($"Show {selection.name}"))
                    {
                        selection.hideFlags &= ~HideFlags.HideInHierarchy;
                        EditorUtility.SetDirty(selection);
                        EditorApplication.DirtyHierarchyWindowSorting();
                    }
                }
                else if (GUILayout.Button($"Hide {selection.name}"))
                {
                    selection.hideFlags |= HideFlags.HideInHierarchy;
                    EditorUtility.SetDirty(selection);
                    EditorApplication.DirtyHierarchyWindowSorting();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Select a GameObject to toggle it", MessageType.Info, true);
            }

            for (var i = 0; i < SceneManager.sceneCount; i++)
            {
                var scene = SceneManager.GetSceneAt(i);
                EditorGUILayout.LabelField("Hidden objects in " + scene.path);

                var rootGameObjects = scene.GetRootGameObjects();
                foreach (var root in rootGameObjects)
                {
                    DrawHidden(root.transform);
                }
            }
        }
Exemplo n.º 16
0
    void HideGO(GameObject _go)
    {
        if (_go == null)
        {
            return;
        }

        GameObject prefab = PrefabUtility.GetCorrespondingObjectFromSource(_go);

        if (!showDebug)
        {
            // if (prefab != null) prefab.hideFlags = HideFlags.HideAndDontSave;
            // else _go.hideFlags = HideFlags.HideAndDontSave;
            _go.hideFlags = HideFlags.HideInHierarchy;
        }
        else
        {
            // if (prefab != null) prefab.hideFlags = HideFlags.DontSave;
            // else _go.hideFlags = HideFlags.DontSave;
            _go.hideFlags = HideFlags.None;
        }
        EditorApplication.DirtyHierarchyWindowSorting();
    }
Exemplo n.º 17
0
        // isolate selection in scene and hierarchy
        public static void selection()
        {
            foreach (GameObject obj in Object.FindObjectsOfType <GameObject>())
            {
                if (!Selection.Contains(obj))                                // don't include selection
                {
                    if (!Selection.activeTransform.IsChildOf(obj.transform)) // don't apply to parent of selection else hierarchy will appear empty
                    {
                        Undo.RegisterFullObjectHierarchyUndo(obj, "Solo Selection");
                        obj.hideFlags = HideFlags.HideInHierarchy;
                        if (obj.GetComponent <Renderer>())
                        {
                            obj.GetComponent <Renderer>().enabled = false;
                        }

                        // used to manually refresh Hierarchy Window
                        EditorApplication.RepaintHierarchyWindow();
                        EditorApplication.DirtyHierarchyWindowSorting();
                    }
                }
            }

            SceneVisibilityManager.instance.Isolate(Selection.gameObjects, true);
        }
        private void ShowInspector()
        {
            //EditorGUIUtility.labelWidth += 35f;

            EditorStyles.foldout.fontStyle = FontStyle.Bold;

            EditorStyles.helpBox.fontSize  = 11;
            EditorStyles.helpBox.fontStyle = FontStyle.Normal;
            //EditorGUI.indentLevel++;
            EditorGUILayout.Space();

            GUILayout.BeginVertical(new GUIStyle(GUI.skin.box));
            GUILayout.Space(4f);

            EditorGUI.BeginChangeCheck();
            EditorGUIUtility.labelWidth -= 50f;
            EditorGUILayout.PropertyField(viewport);
            EditorGUIUtility.labelWidth += 50f;
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                if (viewport.objectReferenceValue != null)
                {
                    viewportMask = myTarget.viewport.GetComponent <Mask> ();
                    myTarget.ArrangeElements();
                }
            }

            if (viewport.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("Viewport reference is missing!", MessageType.Error);
            }
            //EditorGUI.indentLevel--;

            GUILayout.Space(4f);
            GUILayout.EndVertical();
            GUILayout.Space(1f);

            // LAYOUT OPTIONS

            layoutSettings = EditorGUILayout.Foldout(layoutSettings, "Layout Settings", true);
            if (layoutSettings)
            {
                EditorGUI.indentLevel++;
                EditorGUIUtility.labelWidth += 35f;

                EditorGUILayout.Space();
                Rect rect = GUILayoutUtility.GetRect(autoArrangingButton, GUI.skin.button, GUILayout.Height(35f));

                rect.x    += (rect.width - 225f) / 2f - 4;
                rect.width = 225f;

                GUIStyle newStyle = new GUIStyle(GUI.skin.button);
                //newStyle.normal.background.Color

                if (autoArranging.boolValue)
                {
                    autoArrangingButton.text  = "STOP AUTO ARRANGING";
                    newStyle.normal.textColor = new Color(0.7f, 0, 0);
                }
                else
                {
                    autoArrangingButton.text  = "START AUTO ARRANGING";
                    newStyle.normal.textColor = new Color(0, 0.7f, 0);
                }


                newStyle.fontSize  = 13;
                newStyle.fontStyle = FontStyle.Bold;

                if (GUI.Button(rect, autoArrangingButton, newStyle))
                {
                    Undo.RecordObject(myTarget, "Auto Arranging State Change");
                    if (autoArranging.boolValue)
                    {
                        autoArranging.boolValue = false;
                        myTarget.StopAutoArranging();
                    }
                    else
                    {
                        autoArranging.boolValue = true;
                        myTarget.StartAutoArranging();
                    }

                    serializedObject.ApplyModifiedProperties();
                }
                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(alignment);
                if (EditorGUI.EndChangeCheck()) // END CHECKK
                {
                    serializedObject.ApplyModifiedProperties();
                    for (int i = 0; i < elements.arraySize; i++)
                    {
                        Undo.RegisterCompleteObjectUndo(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Elements has changed");
                    }

                    myTarget.ArrangeElements(false);
                    SetupSwipeDetection.Invoke(myTarget, null);
                }

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(layoutMode);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();

                    for (int i = 0; i < elements.arraySize; i++)
                    {
                        Undo.RegisterCompleteObjectUndo(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Elements has changed");
                    }

                    if (layoutMode.enumValueIndex == (int)LayoutMode.Linear)
                    {
                        infiniteScrolling.boolValue = false;
                        circularFactor.floatValue   = 0f;
                    }

                    myTarget.ResetScroll();
                    myTarget.ArrangeElements();
                }
                if (layoutMode.enumValueIndex == (int)LayoutMode.Circular)
                {
                    EditorGUI.BeginChangeCheck(); // BEGIN CHECK
                    EditorGUILayout.PropertyField(curvature);
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.ApplyModifiedProperties();

                        for (int i = 0; i < elements.arraySize; i++)
                        {
                            Undo.RegisterCompleteObjectUndo(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Elements has changed");
                        }

                        myTarget.ResetScroll();
                        myTarget.ArrangeElements();
                    }
                }

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(resizeMode);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();

                    for (int i = 0; i < elements.arraySize; i++)
                    {
                        Undo.RegisterCompleteObjectUndo(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Elements has changed");
                    }

                    if (resizeMode.enumValueIndex != (int)ResizeMode.FitToViewport)
                    {
                        ResetAnchors.Invoke(myTarget, null);
                    }

                    myTarget.ArrangeElements();
                }

                if (resizeMode.enumValueIndex == (int)ResizeMode.PresetSize)
                {
                    EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                    EditorGUILayout.PropertyField(elementsSize);
                    if (EditorGUI.EndChangeCheck()) // END CHECK
                    {
                        for (int i = 0; i < elements.arraySize; i++)
                        {
                            Undo.RegisterCompleteObjectUndo(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Elements has changed");
                        }

                        if (viewport.objectReferenceValue != null)
                        {
                            RectTransform viewportRT = viewport.objectReferenceValue as RectTransform;
                            elementsSize.vector2Value = new Vector2(
                                Mathf.Clamp(elementsSize.vector2Value.x, 0.1f, viewportRT.rect.width),
                                Mathf.Clamp(elementsSize.vector2Value.y, 0.1f, viewportRT.rect.height)
                                );
                        }

                        serializedObject.ApplyModifiedProperties();
                        myTarget.ArrangeElements();
                    }
                }

                EditorGUI.BeginChangeCheck();  // BEGIN CHECK
                EditorGUILayout.PropertyField(invertOrder);
                EditorGUILayout.PropertyField(useMargin);
                EditorGUILayout.PropertyField(elementPadding);

                if (layoutMode.enumValueIndex == (int)LayoutMode.Circular)
                {
                    EditorGUILayout.PropertyField(circularFactor);
                    EditorGUILayout.PropertyField(distanceOffset);
                    EditorGUILayout.PropertyField(rotate);
                }

                if (EditorGUI.EndChangeCheck())  // END CHECK
                {
                    for (int i = 0; i < elements.arraySize; i++)
                    {
                        Undo.RecordObject(elements.GetArrayElementAtIndex(i).objectReferenceValue, "Element Changed");
                    }

                    serializedObject.ApplyModifiedProperties();
                    myTarget.ArrangeElements(false);
                    myTarget.ResetScroll();
                }

                GUILayout.Space(2f);
                EditorGUI.indentLevel--;
                EditorGUIUtility.labelWidth -= 35f;
            }

            // CONTROL OPTIONS

            controlSettings = EditorGUILayout.Foldout(controlSettings, "Control Settings", true);
            if (controlSettings)
            {
                EditorGUI.indentLevel++;
                EditorGUIUtility.labelWidth += 35f;

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(snapMode);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();
                    Undo.RecordObject(myTarget, "Snap Mode has changed");
                    myTarget.ResetScroll();
                    //if (snapMode.enumValueIndex.IsIn<int> ((int)SnapMode.Swipe, (int)SnapMode.Both))
                    //{
                    SetupSwipeDetection.Invoke(myTarget, null);
                    //}
                    //else if (myTarget.SwipeDetect != null)
                    //{
                    //SetupSwipeDetection.Invoke (myTarget, null);
                    GUIUtility.ExitGUI();
                }

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(inertia);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();
                }

                if (inertia.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(decelerationRate);
                    EditorGUILayout.PropertyField(realtimeSelection);
                    EditorGUI.indentLevel--;
                }

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(infiniteScrolling);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();
                    if (layoutMode.enumValueIndex == (int)LayoutMode.Linear)
                    {
                        infiniteScrolling.boolValue = false;
                    }
                    myTarget.ResetScroll();
                }

                //if (snapMode.enumValueIndex != (int)SnapMode.SnapToNearest)
                //{
                //    EditorGUILayout.HelpBox ("Inertia only works in Swipe, Both or None Snap Mode!", MessageType.Warning, true);
                //}

                if (layoutMode.enumValueIndex == (int)LayoutMode.Linear)
                {
                    EditorGUILayout.HelpBox("Infinite Scrolling only works with 'Circular' Layout Mode!", MessageType.Warning, true);
                }

                EditorGUILayout.PropertyField(smoothTransition);
                if (!infiniteScrolling.boolValue)
                {
                    EditorGUILayout.PropertyField(scrollAdditionalLimits);
                }
                EditorGUILayout.PropertyField(transitionSpeed, new GUIContent("Angular Speed"));
                EditorGUILayout.PropertyField(dragDelay);

                GUILayout.Space(2f);
                EditorGUI.indentLevel--;
                EditorGUIUtility.labelWidth -= 35f;
            }

            otherSettings = EditorGUILayout.Foldout(otherSettings, "Other Settings", true);
            if (otherSettings)
            {
                //EditorGUIUtility.labelWidth += 35f;

                //Begin Horizontal
                EditorGUILayout.BeginHorizontal();

                //Begin Vertical
                EditorGUILayout.BeginVertical();
                EditorGUI.indentLevel++;
                EditorGUI.BeginChangeCheck();  // BEGIN CHECK
                EditorGUILayout.PropertyField(useButtons);

                if (EditorGUI.EndChangeCheck())  // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();
                    if (useButtons.boolValue)
                    {
                        CreateButtons();
                    }
                    else
                    {
                        RemoveButtons();
                    }

                    EditorApplication.RepaintHierarchyWindow();
                    EditorApplication.DirtyHierarchyWindowSorting();
                }

                if (indexTable.objectReferenceValue == null)
                {
                    useIndexTable.boolValue = false;
                }

                EditorGUI.BeginChangeCheck();   // BEGIN CHECK
                EditorGUILayout.PropertyField(useIndexTable);
                if (EditorGUI.EndChangeCheck()) // END CHECK
                {
                    serializedObject.ApplyModifiedProperties();
                    if (useIndexTable.boolValue)
                    {
                        CreateIndexTable();
                    }
                    else
                    {
                        RemoveIndexTable();
                    }

                    EditorApplication.RepaintHierarchyWindow();
                    EditorApplication.DirtyHierarchyWindowSorting();
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                if (viewportMask != null)
                {
                    EditorGUILayout.BeginVertical();  //Begin Vertical
                    EditorGUI.BeginChangeCheck();

                    maskViewport    = EditorGUILayout.Toggle(new GUIContent("Mask Viewport", "This will enable/disable the Mask Component of the viewport."), maskViewport);
                    showMaskGraphic = EditorGUILayout.Toggle(new GUIContent("Show Mask Image", "This option will toggle on/off the Show Mask Graphic in the Mask Component of the viewport."), showMaskGraphic);

                    //Undo.RecordObject (this, "Inspector Change");
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.ApplyModifiedProperties();

                        if (myTarget.viewport != null)
                        {
                            Undo.RecordObject(viewportMask, "Inspector Change");
                            viewportMask.enabled         = maskViewport;
                            viewportMask.showMaskGraphic = showMaskGraphic;
                        }
                    }

                    if (myTarget.viewport != null)
                    {
                        maskViewport    = viewportMask.enabled;
                        showMaskGraphic = viewportMask.showMaskGraphic;
                        Repaint();
                        EditorUtility.SetDirty(viewportMask);
                    }

                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(15f);

            EditorGUILayout.PropertyField(onSelectionChange);
            EditorGUILayout.PropertyField(onScrolling);

            EditorStyles.foldout.fontStyle = FontStyle.Normal;

            EditorGUILayout.Space();

            //EditorGUILayout.PropertyField (serializedObject.FindProperty ("text"));
        }
Exemplo n.º 19
0
 private static void ImmediateRepaint()
 {
     EditorApplication.DirtyHierarchyWindowSorting();
 }
 private static void InspectLayers()
 {
     inspectMode = InspectMode.Layers;
     EditorApplication.DirtyHierarchyWindowSorting();
 }
 private static void InspectComponents()
 {
     inspectMode = InspectMode.Components;
     EditorApplication.DirtyHierarchyWindowSorting();
 }
Exemplo n.º 22
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        Undo.RecordObject(_target, "Fog volume directional light modified");
        GUILayout.Space(10);
        GUILayout.BeginVertical("box");
        if (_target._ProminentFogVolume == null)
        {
            GUI.color = Color.red;
        }
        // _target._TargetFogVolume = (FogVolume)EditorGUILayout.ObjectField("Target Fog Volume", _target._TargetFogVolume, typeof(FogVolume), true);

        var FogVolumes = serializedObject.FindProperty("_TargetFogVolumes");

        EditorGUI.indentLevel++;
        EditorGUILayout.PropertyField(FogVolumes, new GUIContent("Target Fog Volume"), true);
        EditorGUI.indentLevel--;
        GUI.color = Color.white;
        GUI.color = new Color(.9f, 1, .9f);
        if (GUILayout.Button("Add all Fog Volumes" /*GUILayout.Width(100)*/))
        {
            _target.AddAllFogVolumesToThisLight();
            _target.Refresh();
            _target.Render();
        }
        if (GUILayout.Button("Remove all Fog Volumes" /*GUILayout.Width(100)*/))
        {
            _target.RemoveAllFogVolumesFromThisLight();
            _target.Refresh();
            _target.Render();
        }
        GUI.color = Color.white;
        _target._CameraVerticalPosition = EditorGUILayout.FloatField(VariableField
                                                                         ("Shadow camera distance", "This is the distance from the shadow camera to the focus point. Increase it if the scene area you want to shade is not completely visible in the shadowmap"), _target._CameraVerticalPosition);
        _target.Size          = (FogVolumeDirectionalLight.Resolution)EditorGUILayout.EnumPopup("Resolution", _target.Size);
        _target._Antialiasing = (FogVolumeDirectionalLight.Antialiasing)EditorGUILayout.EnumPopup("Antialiasing", _target._Antialiasing);
        _target._UpdateMode   = (FogVolumeDirectionalLight.UpdateMode)EditorGUILayout.EnumPopup(VariableField("Update mode", "OnStart: bake shadowmap on start\nInterleaved: skip frames"), _target._UpdateMode);
        if (_target._UpdateMode == FogVolumeDirectionalLight.UpdateMode.Interleaved)
        {
            _target.SkipFrames = EditorGUILayout.IntSlider(VariableField("Skip frames", "Instead updating per-frame, we can skip frames before updating the shadow"), _target.SkipFrames, 0, 10);
        }
        else
        {
            GUI.color = new Color(.9f, 1, .9f);
            if (GUILayout.Button("Refresh" /*GUILayout.Width(100)*/))
            {
                _target.Refresh();
                _target.Render();
                _target.Render();
            }
            GUI.color = Color.white;
        }

        Rect LayerFieldRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(20));

        if (_target.ShadowCamera != null && _target.ShadowCamera.cullingMask == 0)
        {
            GUI.color = Color.red;
        }
        _target.LayersToRender = FogVolumeUtilities.EditorExtension.DrawLayerMaskField(LayerFieldRect, _target.LayersToRender, new GUIContent("Layers to render"));
        GUI.color          = Color.white;
        _target._ScaleMode = (FogVolumeDirectionalLight.ScaleMode)EditorGUILayout.EnumPopup(VariableField("Scale mode",
                                                                                                          "With VolumeX, the camera will take the volume scale.x to adjust its size\nSet it to manual to adjust this size yourself. Useful when you have a large volume and only want to have good shadows at the focus point"), _target._ScaleMode);
        if (_target._ScaleMode == FogVolumeDirectionalLight.ScaleMode.Manual && _target._ProminentFogVolume != null)
        {
            _target.Scale = EditorGUILayout.Slider(VariableField("Zoom", "Scale the view range of the camera.\n It will use the volume size from position 0"), _target.Scale, 10, _target._ProminentFogVolume.fogVolumeScale.x);
        }
        _target._FocusMode = (FogVolumeDirectionalLight.FocusMode)EditorGUILayout.EnumPopup(VariableField("Focus mode", "The camera will focus on the given position. If the volume is not too large the best option would be Volume center"), _target._FocusMode);
        if (_target._FocusMode == FogVolumeDirectionalLight.FocusMode.GameObject)
        {
            _target._GameObjectFocus = (Transform)EditorGUILayout.ObjectField(VariableField("Focus point", "Gameobject used to focus the shadow camera"), _target._GameObjectFocus, typeof(Transform), true);
        }
        _target._FogVolumeShadowMapEdgeSoftness = EditorGUILayout.Slider(VariableField("Edge softness", "Fading range for the edges of the shadowmap"),
                                                                         _target._FogVolumeShadowMapEdgeSoftness, .001f, 1);
        GUILayout.EndVertical();//end box

        #region Debug
        GUILayout.BeginVertical("box");
        if (GUILayout.Button("Debug options", EditorStyles.toolbarButton))
        {
            SHOW_DEBUG_Options = !SHOW_DEBUG_Options;
        }

        if (SHOW_DEBUG_Options)
        {
            _target.CameraVisible = EditorGUILayout.Toggle(VariableField("Show shadow map camera", "Not updating correctly until we click on the hierarchy window :/"), _target.CameraVisible);


            if (_target.GOShadowCamera && _target.GOShadowCamera.hideFlags == HideFlags.HideInHierarchy && _target.CameraVisible)
            {
                _target.GOShadowCamera.hideFlags = HideFlags.None;
                EditorApplication.RepaintHierarchyWindow();
                EditorApplication.DirtyHierarchyWindowSorting();
            }
            if (_target.GOShadowCamera && _target.GOShadowCamera.hideFlags == HideFlags.None && !_target.CameraVisible)
            {
                _target.GOShadowCamera.hideFlags = HideFlags.HideInHierarchy;
                EditorApplication.RepaintHierarchyWindow();
                EditorApplication.DirtyHierarchyWindowSorting();
            }
            _target.ShowMiniature = EditorGUILayout.Toggle("View depth map", _target.ShowMiniature);
        }
        EditorGUI.EndChangeCheck();
        GUI.color = Color.green;
        if (_target._ProminentFogVolume == null)
        {
            EditorGUILayout.HelpBox("Add a Fog Volume now", MessageType.Info);
        }
        if (_target._ProminentFogVolume != null && _target.ShadowCamera != null && _target.ShadowCamera.cullingMask == 0)
        {
            EditorGUILayout.HelpBox("Set the layers used to cast shadows", MessageType.Info);
        }
        GUI.color = Color.white;

        GUI.color = Color.red;
        if (_target._TargetFogVolumes != null)
        {
            foreach (FogVolume fv in _target._TargetFogVolumes)
            {
                if (fv != null)
                {
                    if (fv._FogType == FogVolume.FogType.Uniform)
                    {
                        EditorGUILayout.HelpBox(fv.name +
                                                " Is not a valid Volume. It has to be textured (must use gradient or noise)",
                                                MessageType.Info);
                    }
                }
            }
        }

        GUI.color = Color.white;

        GUI.color = Color.red;
        if (_target._FocusMode == FogVolumeDirectionalLight.FocusMode.GameObject && _target._GameObjectFocus == null)
        {
            EditorGUILayout.HelpBox("Set the focus point object", MessageType.Info);
        }
        GUI.color = Color.white;

        EditorGUILayout.HelpBox("Initial version, experimental", MessageType.Info);
        GUILayout.EndVertical();//end box
        #endregion

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 23
0
        public void update()
        {
            try
            {
                List <QObjectList> objectListList = QObjectList.instances;
                int objectListCount = objectListList.Count;
                if (objectListCount > 0)
                {
                    for (int i = objectListCount - 1; i >= 0; i--)
                    {
                        QObjectList objectList      = objectListList[i];
                        Scene       objectListScene = objectList.gameObject.scene;

                        if (objectListDictionary.ContainsKey(objectListScene) && objectListDictionary[objectListScene] == null)
                        {
                            objectListDictionary.Remove(objectListScene);
                        }

                        if (objectListDictionary.ContainsKey(objectListScene))
                        {
                            if (objectListDictionary[objectListScene] != objectList)
                            {
                                objectListDictionary[objectListScene].merge(objectList);
                                GameObject.DestroyImmediate(objectList.gameObject);
                            }
                        }
                        else
                        {
                            objectListDictionary.Add(objectListScene, objectList);
                        }
                    }

                    foreach (KeyValuePair <Scene, QObjectList> objectListKeyValue in objectListDictionary)
                    {
                        QObjectList objectList = objectListKeyValue.Value;
                        setupObjectList(objectList);
                        if ((showObjectList && ((objectList.gameObject.hideFlags & HideFlags.HideInHierarchy) > 0)) ||
                            (!showObjectList && ((objectList.gameObject.hideFlags & HideFlags.HideInHierarchy) == 0)))
                        {
                            objectList.gameObject.hideFlags ^= HideFlags.HideInHierarchy;
                            EditorApplication.DirtyHierarchyWindowSorting();
                        }
                    }

                    if ((!Application.isPlaying && preventSelectionOfLockedObjects) ||
                        ((Application.isPlaying && preventSelectionOfLockedObjectsDuringPlayMode)) &&
                        isSelectionChanged())
                    {
                        GameObject[]      selections = Selection.gameObjects;
                        List <GameObject> actual     = new List <GameObject>(selections.Length);
                        bool found = false;
                        for (int i = selections.Length - 1; i >= 0; i--)
                        {
                            GameObject gameObject = selections[i];

                            if (objectListDictionary.ContainsKey(gameObject.scene))
                            {
                                bool isLock = objectListDictionary[gameObject.scene].lockedObjects.Contains(selections[i]);
                                if (!isLock)
                                {
                                    actual.Add(selections[i]);
                                }
                                else
                                {
                                    found = true;
                                }
                            }
                        }

                        if (found)
                        {
                            Selection.objects = actual.ToArray();
                        }
                    }

                    lastActiveScene = EditorSceneManager.GetActiveScene();
                    lastSceneCount  = EditorSceneManager.loadedSceneCount;
                }
            }
            catch
            {
            }
        }
    public override void OnInspectorGUI()
    {
        jiggleBone = (SoxAtkJiggleBone)target;

        // GUI레이아웃 시작=======================================================
        //DrawDefaultInspector();
        Undo.RecordObject(target, "Jiggle Bone Changed Settings");
        EditorGUI.BeginChangeCheck();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Unity 3D"))
        {
            ms_targetFlip.boolValue        = false;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.Z;
            ms_lookAxisFlip.boolValue      = false;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
        }
        if (GUILayout.Button("3ds Max"))
        {
            ms_targetFlip.boolValue        = true;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.X;
            ms_lookAxisFlip.boolValue      = true;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Z;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Z;
        }
        if (GUILayout.Button("Maya"))
        {
            ms_targetFlip.boolValue        = true;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.X;
            ms_lookAxisFlip.boolValue      = true;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_animated, new GUIContent("Animated", "This should only be used if Animation is active. Even if it is not Animation, it uses all the changes that operate on Update(). Please use it only when necessary, as it may affect performance."));

        EditorGUILayout.PropertyField(ms_simType, new GUIContent("Simulation Type"));

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_targetDistance, new GUIContent("Target Distance"));
        // PropertyField에서는 ToggleLeft를 사용할 수 없어서 LabelField를 응용해서 ToggleLeft처럼 보이게 함
        EditorGUILayout.PropertyField(ms_targetFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_tension, new GUIContent("Tension"));
        EditorGUILayout.PropertyField(ms_inercia, new GUIContent("Inercia"));

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_lookAxis, new GUIContent("Look Axis"));
        EditorGUILayout.PropertyField(ms_lookAxisFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_sourceUpAxis, new GUIContent("Source Up Axis"));
        EditorGUILayout.PropertyField(ms_sourceUpAxisFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_upWorld, new GUIContent("Up World"));
        if (ms_upWorld.boolValue)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.PropertyField(ms_upNode, new GUIContent("Up Node"));
        GUI.enabled = true;

        GUILayout.BeginHorizontal();
        if (jiggleBone.m_upWorld)
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up World Axis"));
        }
        else
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up Node Axis"));
        }
        EditorGUILayout.LabelField("");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_upnodeControl, new GUIContent("Upnode Control"));

        EditorGUILayout.PropertyField(ms_gravity, new GUIContent("Gravity"));

        EditorGUILayout.PropertyField(ms_colliders, new GUIContent("Colliders"), true); // true 는 includeChildren 옵션임. 시리얼라이즈 된 배열을 처리하려면 true 해줘야함

        SoxAtkJiggleBoneOptions = EditorGUILayout.Foldout(SoxAtkJiggleBoneOptions, "Debug");
        if (SoxAtkJiggleBoneOptions)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(ms_optShowGizmosAtPlaying, new GUIContent("Show Gizmos at Play"));
            EditorGUILayout.PropertyField(ms_optShowGizmosAtEditor, new GUIContent("Show Gizmos at Editor"));
            //ms_optGizmoSize.floatValue = EditorGUILayout.FloatField("Gizmo Size", ms_optGizmoSize.floatValue);
            EditorGUILayout.PropertyField(ms_optGizmoSize, new GUIContent("Gizmo Size"));
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(ms_optShowHiddenNodes, new GUIContent("Show Hidden Nodes"));
            if (jiggleBone.m_hierarchyChanged)
            {
                EditorApplication.DirtyHierarchyWindowSorting();
                jiggleBone.m_hierarchyChanged = false;
            }
            GUI.enabled = true;
            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();    // 이건 시리얼 오브젝트 에디터GUI의 변화를 실제 오브젝트에 반영하는 것
        serializedObject.Update();                     // 이건 오브젝트의 변화를 에디터에 반영하는 것. 예를 들어 Undo 등의 변화라던가 Reset 버튼에 의한 변화가 있으면 업데이트 해줘야한다.

        if (EditorGUI.EndChangeCheck())
        {
            // 프로젝트 창에서 선택한 프리팹을 버전체크하면 문제가 발생한다. Selection.transforms.Length가 0이면 Project View 라는 뜻
            if (Selection.transforms.Length > 0 && Application.isPlaying && jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
            {
                jiggleBone.MyValidate();
            }
        }
        Undo.FlushUndoRecordObjects();

        // GUI레이아웃 끝========================================================
    } // end of OnInspectorGUI()
Exemplo n.º 25
0
        /// <summary>
        /// Draws the entity.
        /// </summary>
        void DrawEntity()
        {
            EditorGUI.BeginChangeCheck();

            var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f);

            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            List <IZComponent> coms = curEntity.GetComponents <IZComponent> ();


            //draw current selected entity
            EditorGUILayout.BeginVertical(entityStyle);

            //show the entity name
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Entity Name: " + curEntity.Name);
            //curEntity.Name = EditorGUILayout.TextField (curEntity.Name);
            EditorGUILayout.EndHorizontal();

            //show component info
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Component x " + coms.Count, GUILayout.MaxWidth(100));
            GUILayout.FlexibleSpace();

            //show the component menu
            IZComponent c = curEntity.EType == EntityType.Entity ?
                            ComponentsPool <IZComponent> .DrawAddComponentMenu() :
                            ComponentsPool <IZComponent> .DrawAddSystemMenu();

            if (c != null)
            {
                var com = ComponentsPool <IZComponent> .CreateComponent(c.GetType());

                curEntity.AddComponent(com);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();


            //Draw Component
            componentColor   = Color.HSVToRGB(0.9f, 0.1f, 0.9f);
            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            ///EditorGUILayout.Space();

            foreach (IZComponent com in coms)
            {
                DrawComponent(com);
            }


            if (EditorGUI.EndChangeCheck())
            {
                // Code to execute if GUI.changed
                // was set to true inside the block of code above.

                if (poolConfig != null && poolConfig.CurPool != null)
                {
                    //Debug.Log("EndChangeCheck");
                    EntityPoolEditorBuildUtils.SaveEntity(curEntity);

                    serializedObject.SetIsDifferentCacheDirty();
                    EditorApplication.DirtyHierarchyWindowSorting();
                    EditorApplication.RepaintProjectWindow();
                    //AssetDatabase.Refresh ();
                    //EditorApplication.
                }
            }
        }
Exemplo n.º 26
0
        private void SceneInfo()
        {
            EditorGUI.BeginChangeCheck();
            GameObject root = sceneCFG.gameObject;

            showTransforms = EditorGUILayout.ToggleLeft("show", root.hideFlags == 0);
            if (GUI.changed)
            {
                if (showTransforms)
                {
                    root.hideFlags = 0;
                }
                else
                {
                    root.hideFlags = HideFlags.HideInHierarchy;
                }
                EditorApplication.DirtyHierarchyWindowSorting();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical("box");
            int size = 1000;

            EditorGUILayout.IntSlider("X", (int)sceneCFG.rect.x, -size, size);
            EditorGUILayout.IntSlider("Y", (int)sceneCFG.rect.y, -size, size);
            int x      = EditorGUILayout.IntSlider("CenterX", (int)sceneCFG.rect.center.x, -size, size);
            int y      = EditorGUILayout.IntSlider("CenterY", (int)sceneCFG.rect.center.y, -size, size);
            int width  = EditorGUILayout.IntSlider("Width", (int)sceneCFG.rect.width, 0, 2000);
            int height = EditorGUILayout.IntSlider("Height", (int)sceneCFG.rect.height, 0, 2000);

            EditorGUILayout.EndVertical();
            Rect rect = new Rect(0, 0, width, height);

            rect.center = new Vector2(x, y);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(sceneCFG, "position");
                sceneCFG.rect = rect;
            }

            SceneView sceneView = SceneView.lastActiveSceneView;

            if (sceneView == null)
            {
                sceneView = SceneView.currentDrawingSceneView;
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.ObjectField(sceneCFG.cutview, typeof(Texture), false);
            sceneCFG.preview = (Texture)EditorGUILayout.ObjectField("preview", sceneCFG.preview, typeof(Texture), false);
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("GetPreview"))
            {
                int   textureSize = (int)(rect.height * 2);
                float aspect      = rect.width / rect.height;
                int   textWidth   = Mathf.RoundToInt(aspect * textureSize);
                if (renderTexture == null || renderTexture.height != textureSize || renderTexture.width != textWidth)
                {
                    renderTexture           = new RenderTexture(textWidth, textureSize, 24);
                    renderTexture.hideFlags = HideFlags.HideAndDontSave;
                }
                else
                {
                    renderTexture.DiscardContents();
                }
                Camera camera = sceneView.camera;

                Vector3 v = new Vector3(rect.x + rect.width / 2f, 0, rect.y + rect.height / 2f);
                sceneView.orthographic     = true;
                sceneView.isRotationLocked = true;
                sceneView.LookAt(v, Quaternion.Euler(90, 0, 0));
                sceneView.Repaint();
                EditorApplication.delayCall += () =>
                {
                    RenderTexture oldRenderTexture    = camera.targetTexture;
                    float         oldAspect           = camera.aspect;
                    float         oldOrthographicSize = camera.orthographicSize;

                    bool oldFog = RenderSettings.fog;
                    Unsupported.SetRenderSettingsUseFogNoDirty(false);

                    camera.orthographicSize = rect.height / 2f;
                    camera.aspect           = aspect;
                    camera.targetTexture    = renderTexture;
                    camera.Render();

                    camera.orthographicSize = oldOrthographicSize;
                    camera.aspect           = oldAspect;
                    camera.targetTexture    = null;
                    Unsupported.SetRenderSettingsUseFogNoDirty(oldFog);

                    string name = "preview";
                    SaveRenderTextureToPNG(renderTexture, aspect, name);
                    AssetDatabase.Refresh();

                    string path = getSceneAssetPrefix() + "/" + name + ".png";
                    sceneCFG.cutview = sceneCFG.preview = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                    sceneView.Repaint();
                };
            }
            if (GUILayout.Button("GetHeightmap"))
            {
                int w = (int)(rect.width * 10);
                int h = (int)(rect.height * 10);

                Texture2D texture2D = new Texture2D(w, h, TextureFormat.ARGB32, false);
                texture2D.hideFlags = HideFlags.HideAndDontSave;
                Color[] colors = new Color[w * h];

                NavMeshTriangulation tmpNavMeshTriangulation = NavMesh.CalculateTriangulation();
                Vector3[]            vertices = tmpNavMeshTriangulation.vertices;
                int[]     indices             = tmpNavMeshTriangulation.indices;
                int       len       = indices.Length / 3;
                HeightMap heightMap = new HeightMap(w, h, TextureFormat.ARGB32, false);

                for (int i = 0; i < len; i++)
                {
                    int     index = indices[i * 3 + 0];
                    Vector3 v0    = Trans(vertices[index]);
                    index = indices[i * 3 + 1];
                    Vector3 v1 = Trans(vertices[index]);
                    index = indices[i * 3 + 2];
                    Vector3 v2 = Trans(vertices[index]);
                    heightMap.DrawTriangle(v0, v1, v2, Color.red);

                    if (i % 500 == 0)
                    {
                        ShowProgress(i, len);
                    }
                }
                EditorUtility.ClearProgressBar();
                texture2D = heightMap.EndDraw();

                string pngName = "heightMap";
                saveTexture(texture2D, pngName);

                Texture2D.DestroyImmediate(texture2D);
                AssetDatabase.Refresh();
            }
            if (GUILayout.Button("ExportNav"))
            {
                Renderer[]                 renderers         = GameObject.FindObjectsOfType <Renderer>();
                List <MeshFilter>          meshRenderers     = new List <MeshFilter>();
                List <SkinnedMeshRenderer> skinMeshRenderers = new List <SkinnedMeshRenderer>();
                foreach (Renderer renderer in renderers)
                {
                    if (renderer is MeshRenderer)
                    {
                        GameObject         go       = renderer.gameObject;
                        SerializedObject   so       = new SerializedObject(go);
                        SerializedProperty property = so.FindProperty("m_StaticEditorFlags");
                        if ((property.intValue & 8) != 0)
                        {
                            MeshFilter f = renderer.gameObject.GetComponent <MeshFilter>();
                            if (f)
                            {
                                meshRenderers.Add(f);
                            }
                        }
                    }
                }

                if (meshRenderers.Count == 0)
                {
                    List <GameObject> list = new List <GameObject>();
                    SceneManager.GetActiveScene().GetRootGameObjects(list);
                    List <Renderer> rList = new List <Renderer>();
                    foreach (GameObject go in list)
                    {
                        Renderer[] t = go.GetComponentsInChildren <Renderer>(true);
                        rList.AddRange(t);
                    }

                    foreach (Renderer renderer in rList)
                    {
                        if (renderer is MeshRenderer)
                        {
                            GameObject         go       = renderer.gameObject;
                            SerializedObject   so       = new SerializedObject(go);
                            SerializedProperty property = so.FindProperty("m_StaticEditorFlags");
                            if ((property.intValue & 8) != 0)
                            {
                                MeshFilter f = renderer.gameObject.GetComponent <MeshFilter>();
                                if (f)
                                {
                                    meshRenderers.Add(f);
                                }
                            }
                        }
                    }
                }


                NavObjectData v = new NavObjectData();
                v.export(meshRenderers.ToArray(), skinMeshRenderers.ToArray());

                FileInfo fileInfo = new FileInfo(Application.dataPath);
                string   prefix   = Path.Combine(fileInfo.Directory.FullName, "ReleaseResource/NAV/");
                if (Directory.Exists(prefix) == false)
                {
                    Directory.CreateDirectory(prefix);
                }
                v.save(prefix + "Meshes/RootScene.obj");

                System.Diagnostics.Process.Start(prefix + "Recast.bat");
                System.Diagnostics.Process.Start(prefix);
            }

            if (GUILayout.Button("CopyRect"))
            {
                IntRectange intRectange = new IntRectange();
                intRectange.CopyFrom(sceneCFG.rect);
                string v = intRectange.x + "," + intRectange.y + "," + intRectange.width + "," + intRectange.height;
                EditorGUIUtility.systemCopyBuffer = v;
                ShowNotification(new GUIContent("已复制"));
            }

            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                sceneView.Repaint();
            }
        }
Exemplo n.º 27
0
    public override void OnInspectorGUI()
    {
        jiggleBone = (SoxAtkJiggleBoneSimple)target;

        // GUI레이아웃 시작=======================================================
        //DrawDefaultInspector();
        Undo.RecordObject(target, "Jiggle Bone Changed Settings");
        EditorGUI.BeginChangeCheck();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_targetDistance, new GUIContent("Target Distance"));
        // PropertyField에서는 ToggleLeft를 사용할 수 없어서 LabelField를 응용해서 ToggleLeft처럼 보이게 함
        EditorGUILayout.PropertyField(ms_targetFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_tension, new GUIContent("Tension"));
        EditorGUILayout.PropertyField(ms_inercia, new GUIContent("Inercia"));

        EditorGUILayout.PropertyField(ms_upWorld, new GUIContent("Up World"));
        if (ms_upWorld.boolValue)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.PropertyField(ms_upNode, new GUIContent("Up Node"));
        GUI.enabled = true;

        GUILayout.BeginHorizontal();
        if (jiggleBone.m_upWorld)
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up World Axis"));
        }
        else
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up Node Axis"));
        }
        EditorGUILayout.LabelField("");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_upnodeControl, new GUIContent("Upnode Control"));

        EditorGUILayout.PropertyField(ms_gravity, new GUIContent("Gravity"));

        EditorGUILayout.PropertyField(ms_colliders, new GUIContent("Colliders"), true); // true 는 includeChildren 옵션임. 시리얼라이즈 된 배열을 처리하려면 true 해줘야함

        SoxAtkJiggleBoneOptions = EditorGUILayout.Foldout(SoxAtkJiggleBoneOptions, "Debug");
        if (SoxAtkJiggleBoneOptions)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(ms_optShowGizmosAtPlaying, new GUIContent("Show Gizmos at Play"));
            EditorGUILayout.PropertyField(ms_optShowGizmosAtEditor, new GUIContent("Show Gizmos at Editor"));
            //ms_optGizmoSize.floatValue = EditorGUILayout.FloatField("Gizmo Size", ms_optGizmoSize.floatValue);
            EditorGUILayout.PropertyField(ms_optGizmoSize, new GUIContent("Gizmo Size"));
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(ms_optShowHiddenNodes, new GUIContent("Show Hidden Nodes"));
            if (jiggleBone.m_hierarchyChanged)
            {
                EditorApplication.DirtyHierarchyWindowSorting();
                jiggleBone.m_hierarchyChanged = false;
            }
            GUI.enabled = true;
            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();    // 이건 시리얼 오브젝트 에디터GUI의 변화를 실제 오브젝트에 반영하는 것
        serializedObject.Update();                     // 이건 오브젝트의 변화를 에디터에 반영하는 것. 예를 들어 Undo 등의 변화라던가 Reset 버튼에 의한 변화가 있으면 업데이트 해줘야한다.

        if (EditorGUI.EndChangeCheck())
        {
            // 프로젝트 창에서 선택한 프리팹을 버전체크하면 문제가 발생한다. Selection.transforms.Length가 0이면 Project View 라는 뜻
            if (Selection.transforms.Length > 0 && Application.isPlaying && jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
            {
                jiggleBone.MyValidate();
            }
        }
        Undo.FlushUndoRecordObjects();

        // GUI레이아웃 끝========================================================
    } // end of OnInspectorGUI()