///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DrawAdvancedButtons
        /// # Draw all advanced buttons
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void DrawAdvancedButtons()
        {
            bool drawThis = true;

            if (!configSaver.parameters.showAdvancedActionsAlways && (systemMode != cSystemMode.edition))
            {
                drawThis = false;
            }

            if (drawThis)
            {
                configSaver.parameters.showAdvancedActions = EditorGUILayout.Foldout(configSaver.parameters.showAdvancedActions, new GUIContent("Advanced actions", "Show advanced actions"));

                if (configSaver.parameters.showAdvancedActions)
                {
                    EditorBasicFunctions.DrawEditorBox("Advanced actions", Color.yellow, position);

                    EditorGUILayout.Separator();
                    EditorGUILayout.Separator();

                    float buttonsScale = position.width / 6;

                    if (cleanAlSceneScriptsConfirmationMode)
                    {
                        EditorBasicFunctions.DrawEditorBox("Do you really want to clean all the scripts?", Color.white, position);

                        // clean all scripts
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorButton("NoButton", "Don't clean", new Vector2(buttonsScale, buttonsScale), true, false, false, true))
                        {
                            cleanAlSceneScriptsConfirmationMode = false;
                        }

                        EditorBasicFunctions.GetEditorButton("EmptyButton", "", new Vector2(buttonsScale, buttonsScale), false, true, true, true);
                        EditorBasicFunctions.GetEditorButton("EmptyButton", "", new Vector2(buttonsScale, buttonsScale), false, true, true, true);

                        if (EditorBasicFunctions.GetEditorButton("YesButton", "Continue cleaning", new Vector2(buttonsScale, buttonsScale), true, false, false, true))
                        {
                            CleanAllSceneScriptsAction();
                            cleanAlSceneScriptsConfirmationMode = false;
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        // clean all scripts
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorTextButton("CLEAN SCRIPTS", "Clean all the scripts in the scene, for example to use without this editor extension in the system", position))
                        {
                            cleanAlSceneScriptsConfirmationMode = true;
                        }

                        // create new decal
                        if (EditorBasicFunctions.GetEditorTextButton("CREATE DECAL", "Create a new decal just selecting textures, type and folder", position))
                        {
                            CreateDecalWindow window = ScriptableObject.CreateInstance <CreateDecalWindow>();
                            window.name = "Create new decal";
#if UNITY_5_0
                            window.title = window.name;
#else
                            window.titleContent = new GUIContent(window.name);
#endif
                            window.Show();
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        EditorGUILayout.Separator();

                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();


                        // lock all future time lockable decals
                        if (EditorBasicFunctions.GetEditorTextButton("LOCK DECALS", "Mark all 'futureTimeLockableShape' decals as locked", position))
                        {
                            foreach (GenericMeshDecal actualDecal in GameObject.FindObjectsOfType <GenericMeshDecal>())
                            {
                                if (actualDecal.futureTimeLockableShape)
                                {
                                    actualDecal.lockedShapeAlways = true;
                                }
                            }
                        }

                        // merge decals
                        if (EditorBasicFunctions.GetEditorTextButton("MERGE DECALS", "Merge all selected decals into single one mesh", position))
                        {
                            MergeDecalWindow window = ScriptableObject.CreateInstance <MergeDecalWindow>();
                            window.name = "Merge new decal";
#if UNITY_5_0
                            window.title = window.name;
#else
                            window.titleContent = new GUIContent(window.name);
#endif
                            window.Show();
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }

                    EditorGUILayout.Separator();
                    EditorGUILayout.Separator();
                    EditorBasicFunctions.DrawLineSeparator();
                }
            }
        }
Esempio n. 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DrawEditionMode
        /// # Draw al gui buttons, checboxes, ... to handle edition mode
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void DrawExtraOptions()
        {
            bool drawThis = true;

            if (systemMode != cSystemMode.edition)
            {
                drawThis = false;
            }

            if (drawThis)
            {
                configSaver.parameters.showExtraOptions = EditorGUILayout.Foldout(configSaver.parameters.showExtraOptions, new GUIContent("Extra options", "Show extra options"));

                if (configSaver.parameters.showExtraOptions)
                {
                    EditorBasicFunctions.DrawEditorBox("Extra options", Color.yellow, position);

                    if (splineDecalModeEnabled)
                    {
                        if (!configSaver.parameters.hideBasicHelp)
                        {
                            EditorGUILayout.HelpBox("You can insert new waypoints using actual selected insert mode. Once you create waypoints just select one decal to make it to follow a path", MessageType.Info);
                        }

                        EditorGUILayout.Separator();

                        closedWaypointSpline = EditorGUILayout.Toggle(new GUIContent("Closed spline", "Close the spline to finish in the initial point"), closedWaypointSpline);
                        loopWaypointSpline   = EditorGUILayout.Toggle(new GUIContent("Loop spline", "Update position in a cotinuous loop"), loopWaypointSpline);

                        EditorGUILayout.Separator();

                        // build spline decal
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorTextButton("BUILD SPLINE DECAL", "Create a spline decal using actual waypoints", position))
                        {
                            List <WayPoint> wayPointList = new List <WayPoint> ();
                            List <Object>   objectList   = GameObject.FindObjectsOfType(typeof(WayPoint)).ToList();

                            for (int i = 0; i < objectList.Count; i++)
                            {
                                wayPointList.Add(objectList [i] as WayPoint);
                            }

                            wayPointList = wayPointList.OrderBy(x => x.index).ToList();

                            if (wayPointList.Count >= 2)
                            {
                                if (Selection.gameObjects.Count() == 1)
                                {
                                    GenericPathFollower actualPathFollower = Selection.gameObjects [0].GetComponent <GenericPathFollower> ();

                                    if (!actualPathFollower)
                                    {
                                        actualPathFollower = Selection.gameObjects [0].gameObject.AddComponent <GenericPathFollower> ();
                                    }

                                    actualPathFollower.Create(wayPointList, closedWaypointSpline, loopWaypointSpline);
                                }
                                else
                                {
                                    EditorUtility.DisplayDialog("WARNING", "Please, select one object only", "OK");
                                }
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("WARNING", "Please, insert at least two waypoints", "OK");
                            }
                        }

                        // remove waypoints
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorTextButton("REMOVE ALL WAYPOINTS", "Remove all waypoins in scene", position))
                        {
                            GameObject wpContainer = GameObject.Find("_DECAL_WAYPOINTS");
                            DestroyImmediate(wpContainer);

                            List <WayPoint> wayPointList = new List <WayPoint> ();
                            List <Object>   objectList   = GameObject.FindObjectsOfType(typeof(WayPoint)).ToList();

                            for (int i = 0; i < objectList.Count; i++)
                            {
                                wayPointList.Add(objectList [i] as WayPoint);
                            }

                            foreach (WayPoint wp in wayPointList)
                            {
                                DestroyImmediate(wp.gameObject);
                            }
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        EditorGUILayout.Separator();


                        // leave spline decal mode
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorTextButton("LEAVE", "Leave spline decal mode", position))
                        {
                            splineDecalModeEnabled = false;
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.Separator();

                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();

                        if (EditorBasicFunctions.GetEditorTextButton("SPLINE DECAL MODE", "Go to spline decal mode", position))
                        {
                            splineDecalModeEnabled = true;
                        }

                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }


                    EditorGUILayout.Separator();

                    EditorBasicFunctions.DrawLineSeparator();
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DrawObjectlList
        /// # Draw actual selectable prefab list (looking inside it's folder) and handle dev's selections
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static GameObject DrawPrefabList(GameObject actualGameObject, Rect position)
        {
            // save actual gui color
            Color actualGuiColor = GUI.color;
            Color bgColor        = GUI.backgroundColor;

            GameObject selectedGameObject = actualGameObject;

            EditorGUILayout.Separator();

            // get actual prefab list
            bool redoTheList = false;

            for (int i = 0; i < prefabList.Count; i++)
            {
                if (AssetDatabase.GetAssetPath(prefabList [i]).Length < 2)
                {
                    redoTheList = true;
                }
            }

            if (redoTheList)
            {
                Debug.Log("Prefab deleted, redo prefab decal list");
            }

            if ((prefabList.Count <= 0) || redoTheList)
            {
                prefabList = EditorBasicFunctions.GetPrefabList();
            }

            // calculate paths
            List <string> localTotalGameObjectPathList = new List <string> ();

            for (int i = 0; i < prefabList.Count; i++)
            {
                string totalPath  = AssetDatabase.GetAssetPath(prefabList [i]);
                string actualPath = Path.GetDirectoryName(totalPath);

                int index = 0;

                for (int j = 0; j < actualPath.Length; j++)
                {
                    if (actualPath [j] == '/')
                    {
                        index = j;
                    }
                }

                string finalPath = actualPath.Substring(index + 1, actualPath.Length - index - 1);

                localTotalGameObjectPathList.Add(finalPath);
            }

            List <string> localGameObjectPathList = localTotalGameObjectPathList.Distinct().ToList();

            if (!showSystemFolders)
            {
                localGameObjectPathList.Remove("System");
            }

            //print ("------------------------------------------");
            //for (int i = 0; i < localGameObjectPathList.Count; i++)
            //{
            //print (localGameObjectPathList [i]);
            //}

            EditorGUILayout.Separator();
            GenericObject.actualFolderIndex = EditorGUILayout.Popup(GenericObject.actualFolderIndex, localGameObjectPathList.ToArray(), new GUILayoutOption[] { GUILayout.Width(0.81f * position.width) });

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (EditorBasicFunctions.GetEditorTextButton("Refresh", "Refresh the list, just in case", position))
            {
                RefreshLists();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            string selectedGameObjectPath = BasicDefines.NOT_DEFINED;

            if (localGameObjectPathList.Count > 0)
            {
                selectedGameObjectPath = localGameObjectPathList [GenericObject.actualFolderIndex];
            }


            // test some things
            int        numberOfObjectsPerLine = 4;
            int        cont  = 0;
            bool       begin = false;
            bool       actualSelectedElementIsInSelectedPathList = false;
            GameObject firstElementInActualPath = null;


            // draw objects in editor window
            for (int i = 0; i < Mathf.Ceil((float)prefabList.Count); i++)
            {
                if (localTotalGameObjectPathList [i] == selectedGameObjectPath)
                {
                    if (firstElementInActualPath == null)
                    {
                        firstElementInActualPath = prefabList [i];
                    }

                    if ((selectedGameObject == prefabList [i]))
                    {
                        actualSelectedElementIsInSelectedPathList = true;
                    }

                    if (cont % numberOfObjectsPerLine == 0)
                    {
                        GUILayout.BeginHorizontal();
                        begin = true;
                    }

                    Texture previsualization = BasicFunctions.GetThumbnail(prefabList [i]);

                    Texture unityPreview = AssetPreview.GetAssetPreview(actualGameObject);

                    if (unityPreview)
                    {
                        //previsualization = unityPreview;
                    }

                    if (actualGameObject == prefabList [i])
                    {
                        GUI.color           = new Color(1, 1, 1, 1);
                        GUI.backgroundColor = new Color(0.6f, 0.0f, 0.6f, 1f);
                    }
                    else
                    {
                        GUI.color           = new Color(1, 1, 1, 1f);
                        GUI.backgroundColor = new Color(1, 1, 1, 0.3f);
                    }

                    float buttonsScale = 0.94f * position.width / (numberOfObjectsPerLine + 0.3f);

                    bool selected = GUILayout.Button(new GUIContent(previsualization, prefabList [i].name), new GUILayoutOption[] {
                        GUILayout.Width(buttonsScale),
                        GUILayout.Height(buttonsScale)
                    });


                    if (selected)
                    {
                        selectedGameObject = prefabList [i];
                    }

                    if (cont % numberOfObjectsPerLine == numberOfObjectsPerLine - 1)
                    {
                        GUILayout.EndHorizontal();
                        begin = false;
                    }

                    cont++;
                }
            }

            if (!actualSelectedElementIsInSelectedPathList)
            {
                //print ("Change to firstElementInActualPath: " + firstElementInActualPath.name);
                selectedGameObject = firstElementInActualPath;
            }

            if (begin)
            {
                EditorGUILayout.EndHorizontal();
            }

            // restore Gui Color
            GUI.color           = actualGuiColor;
            GUI.backgroundColor = bgColor;


            //return selected game object
            return(selectedGameObject);
        }