コード例 #1
0
        protected void OnGUI()
        {
            try
            {
                if (Event.current.type == EventType.Layout)
                {
                    EditorDispatcher.Update();
                }

                if (!mFocusedOnce)
                {
                    // Somehow the prevents the dialog from jumping when dragged
                    // NOTE(rafa): We cannot do every frame because the modal kidnaps focus for all processes (in mac at least)
                    Focus();
                    mFocusedOnce = true;
                }

                ProcessKeyActions();

                if (mIsClosed)
                {
                    return;
                }

                GUI.Box(new Rect(0, 0, position.width, position.height), GUIContent.none);
                GUI.Box(new Rect(0, 0, position.width, 16), GUIContent.none, EditorStyles.toolbar);

                float margin    = 25;
                float marginTop = 40;
                using (new EditorGUILayout.HorizontalScope(GUILayout.Height(position.height)))
                {
                    GUILayout.Space(margin);
                    using (new EditorGUILayout.VerticalScope(GUILayout.Height(position.height)))
                    {
                        GUILayout.Space(marginTop);
                        OnModalGUI();
                        GUILayout.Space(margin);
                    }
                    GUILayout.Space(margin);
                }

                var   lastRect      = GUILayoutUtility.GetLastRect();
                float desiredHeight = lastRect.yMax;
                Rect  newPos        = position;
                newPos.height = desiredHeight;
                if (position.height < desiredHeight)
                {
                    position = newPos;
                }

                if (Event.current.type == EventType.Repaint)
                {
                    if (mIsCompleted)
                    {
                        mIsClosed = true;
                        Close();
                    }
                }
            }
            finally
            {
                if (mIsClosed)
                {
                    EditorGUIUtility.ExitGUI();
                }
            }
        }
コード例 #2
0
        void UpdateEditMode()
        {
            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

            EditorGUILayout.PropertyField(barycentricWeight);
            EditorGUILayout.PropertyField(normalAlignmentWeight);
            EditorGUILayout.PropertyField(elevationWeight);

            EditorGUI.BeginChangeCheck();
            paintMode    = GUILayout.Toggle(paintMode, new GUIContent("Paint skin", Resources.Load <Texture2D>("PaintButton")), "LargeButton");
            Tools.hidden = paintMode || subject == SubjectBeingEdited.Master;
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }

            // Buttons:
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Bind") && masterObject != null && slaveObject != null)
            {
                EditorUtility.SetDirty(target);
                CoroutineJob job = new CoroutineJob();
                routine = job.Start(skinMap.Bind());
                EditorCoroutine.ShowCoroutineProgressBar("Generating skinmap...", ref routine);
                EditorGUIUtility.ExitGUI();
            }

            if (GUILayout.Button("Done"))
            {
                EditorApplication.delayCall += ExitSkinEditMode;
            }

            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            // skin channel selector:
            if (paintMode)
            {
                EditorGUILayout.Space();
                GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

                EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

                // Brush parameters:
                paintBrush.radius      = EditorGUILayout.Slider("Brush size", paintBrush.radius, 0.0001f, 0.5f);
                paintBrush.innerRadius = 1;
                paintBrush.opacity     = 1;

                EditorGUI.BeginChangeCheck();
                if (paintBrush.brushMode.needsInputValue)
                {
                    currentProperty.PropertyField();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(new GUIContent("Fill"), EditorStyles.miniButtonLeft))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.FillChannel(skinMap.m_MasterChannels, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.FillChannel(skinMap.m_SlaveChannels, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Clear"), EditorStyles.miniButtonMid))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.ClearChannel(skinMap.m_MasterChannels, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.ClearChannel(skinMap.m_SlaveChannels, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Copy"), EditorStyles.miniButtonMid))
                {
                    targetSkinChannel = currentProperty.GetDefault();
                }

                if (GUILayout.Button(new GUIContent("Paste"), EditorStyles.miniButtonRight))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.CopyChannel(skinMap.m_MasterChannels, targetSkinChannel, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.CopyChannel(skinMap.m_SlaveChannels, targetSkinChannel, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                GUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Slave transform", EditorStyles.boldLabel);
            if (GUILayout.Button("Reset", EditorStyles.miniButton))
            {
                skinMap.m_SlaveTransform.Reset();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_SlaveTransform"));

            EditorGUILayout.EndVertical();
        }
コード例 #3
0
    public override void OnInspectorGUI()
    {
        PaintCompleteChecker checker = target as PaintCompleteChecker;
        RenderTexturePainter painter = checker.gameObject.GetComponent <RenderTexturePainter>();

        EditorGUILayout.Space();
        serializedObject.Update();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("gridDefaultStatus"), true);
        if (painter == null)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sourceTexture"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("penTexture"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("gridScale"), true);
        }
        EditorGUILayout.PropertyField(serializedObject.FindProperty("enableColor"), true);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("disableColor"), true);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("checkData"), true);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("canResetData"), true);
        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.Space();
        serializedObject.Update();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("editorBrushSize"), true);
        serializedObject.ApplyModifiedProperties();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("(Ctrl+)Read Data"))
        {
            ReadGrid();
        }
        SpriteRenderer sr = checker.gameObject.GetComponent <SpriteRenderer>();

        if (sr == null && GUILayout.Button("Show Source Tex"))
        {
            Texture2D tex = checker.sourceTexture as Texture2D;
            if (painter && painter.sourceTexture)
            {
                tex = painter.sourceTexture as Texture2D;
            }
            if (tex)
            {
                SpriteRenderer render = checker.GetComponent <SpriteRenderer>();
                if (!render)
                {
                    render = checker.gameObject.AddComponent <SpriteRenderer>();
                }
                render.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f);
            }
        }
        else if (sr && GUILayout.Button("Remove SpriteRenderer"))
        {
            DestroyImmediate(sr);
            EditorGUIUtility.ExitGUI();
        }
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("(Ctrl+)Create Data"))
        {
            CreateGrid();
        }
        if (GUILayout.Button("Save Grid Data"))
        {
            SaveDataToFile();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.TextArea("Cmd/Ctrl + Mouse: Add Point\nAlt + Mouse : Remove Point");
    }
コード例 #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUI.enabled = rope.Initialized;
            EditorGUI.BeginChangeCheck();
            editMode = GUILayout.Toggle(editMode, new GUIContent("Edit particles", Resources.Load <Texture2D>("EditParticles")), "LargeButton");
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
            GUI.enabled = true;

            EditorGUILayout.LabelField("Status: " + (rope.Initialized ? "Initialized":"Not initialized"));

            GUI.enabled = (rope.ropePath != null);
            if (GUILayout.Button("Initialize"))
            {
                if (!rope.Initialized)
                {
                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                    CoroutineJob job = new CoroutineJob();
                    routine = job.Start(rope.GeneratePhysicRepresentationForMesh());
                    EditorCoroutine.ShowCoroutineProgressBar("Generating physical representation...", ref routine);
                    EditorGUIUtility.ExitGUI();
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Actor initialization", "Are you sure you want to re-initialize this actor?", "Ok", "Cancel"))
                    {
                        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                        CoroutineJob job = new CoroutineJob();
                        routine = job.Start(rope.GeneratePhysicRepresentationForMesh());
                        EditorCoroutine.ShowCoroutineProgressBar("Generating physical representation...", ref routine);
                        EditorGUIUtility.ExitGUI();
                    }
                }
            }
            GUI.enabled = true;

            GUI.enabled = rope.Initialized;
            if (GUILayout.Button("Set Rest State"))
            {
                Undo.RecordObject(rope, "Set rest state");
                rope.PullDataFromSolver(ParticleData.POSITIONS | ParticleData.VELOCITIES);
            }
            GUI.enabled = true;

            if (rope.ropePath == null)
            {
                EditorGUILayout.HelpBox("Rope path spline is missing.", MessageType.Info);
            }

            Editor.DrawPropertiesExcluding(serializedObject, "m_Script", "chainLinks");

            // Apply changes to the serializedProperty
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
        private void RenderManualConstraintMenu()
        {
            for (int i = 0; i < selectedConstraints.arraySize; i++)
            {
                SerializedProperty constraintProperty = selectedConstraints.GetArrayElementAtIndex(i);
                var buttonAction = RenderManualConstraintItem(constraintProperty, true);
                if (buttonAction == EntryAction.Detach)
                {
                    indicesToRemove.Add(i);
                }
                else if (buttonAction == EntryAction.Highlight)
                {
                    string constraintName = constraintProperty.objectReferenceValue.GetType().Name;
                    Highlighter.Highlight("Inspector", $"{ObjectNames.NicifyVariableName(constraintName)} (Script)");
                    EditorGUIUtility.ExitGUI();
                }
            }

            // add buttons
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (EditorGUILayout.DropdownButton(new GUIContent("Add Entry", "Attach an already existing component from this gameobject to the constraint manager selection."), FocusType.Keyboard))
                    {
                        // create the menu and add items to it
                        GenericMenu menu = new GenericMenu();

                        var constraints = constraintManager.gameObject.GetComponents <TransformConstraint>();

                        bool hasEntries = false;
                        foreach (var constraint in constraints)
                        {
                            // only show available constraints that haven't been added yet
                            var existingConstraint = constraintManager.SelectedConstraints.Find(t => t == constraint);
                            if (existingConstraint == null)
                            {
                                hasEntries = true;
                                string constraintName = constraint.GetType().Name;
                                menu.AddItem(new GUIContent(constraintName), false, t =>
                                             AttachConstraint((TransformConstraint)t), constraint);
                            }
                        }

                        // if all constraint components are already part of the list display disabled "no constraint available" entry
                        if (hasEntries == false)
                        {
                            var guiEnabledRestore = GUI.enabled;
                            GUI.enabled = false;
                            menu.AddItem(new GUIContent("No constraint available",
                                                        "Either there's no constraint attached to this game object or all available constraints " +
                                                        "are already part of the list."), false, null);
                            GUI.enabled = guiEnabledRestore;
                        }

                        menu.ShowAsContext();
                    }

                    if (EditorGUILayout.DropdownButton(new GUIContent("Add New Constraint", "Add a constraint to the gameobject and attach to this constraint manager selection."), FocusType.Keyboard))
                    {
                        // create the menu and add items to it
                        GenericMenu menu = new GenericMenu();

                        var type  = typeof(TransformConstraint);
                        var types = AppDomain.CurrentDomain.GetAssemblies()
                                    .SelectMany(s => s.GetLoadableTypes())
                                    .Where(p => type.IsAssignableFrom(p) && !p.IsAbstract);

                        foreach (var derivedType in types)
                        {
                            menu.AddItem(new GUIContent(derivedType.Name), false, t =>
                                         AddNewConstraint((Type)t), derivedType);
                        }

                        menu.ShowAsContext();
                    }
                }
            }
        }
コード例 #6
0
        public void DoGUI(HierarchyFrameDataView frameDataView, bool fetchData, ref bool updateViewLive)
        {
            using (m_DoGUIMarker.Auto())
            {
                if (Event.current.type != EventType.Layout && m_ThreadIndexDuringLastNonLayoutEvent != threadIndex)
                {
                    m_ThreadIndexDuringLastNonLayoutEvent = threadIndex;
                    EditorGUIUtility.ExitGUI();
                }
                InitIfNeeded();

                var collectingSamples = ProfilerDriver.enabled && (ProfilerDriver.profileEditor || EditorApplication.isPlaying);
                var isSearchAllowed   = string.IsNullOrEmpty(treeView.searchString) || !(collectingSamples && ProfilerDriver.deepProfiling);

                var isDataAvailable = frameDataView != null && frameDataView.valid;

                var showDetailedView = isDataAvailable && m_DetailedViewType != DetailedViewType.None;
                if (showDetailedView)
                {
                    SplitterGUILayout.BeginHorizontalSplit(m_DetailedViewSpliterState);
                }

                // Hierarchy view area
                GUILayout.BeginVertical();

                DrawToolbar(frameDataView, showDetailedView, ref updateViewLive);

                if (!string.IsNullOrEmpty(dataAvailabilityMessage))
                {
                    GUILayout.Label(dataAvailabilityMessage, BaseStyles.label);
                }
                else if (!isDataAvailable)
                {
                    if (!fetchData && !updateViewLive)
                    {
                        GUILayout.Label(BaseStyles.liveUpdateMessage, BaseStyles.label);
                    }
                    else
                    {
                        GUILayout.Label(BaseStyles.noData, BaseStyles.label);
                    }
                }
                else if (!isSearchAllowed)
                {
                    GUILayout.Label(BaseStyles.disabledSearchText, BaseStyles.label);
                }
                else
                {
                    var rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandHeight(true));
                    m_TreeView.SetFrameDataView(frameDataView);
                    m_TreeView.OnGUI(rect);
                }

                GUILayout.EndVertical();

                if (showDetailedView)
                {
                    GUILayout.BeginVertical();

                    // Detailed view area
                    EditorGUILayout.BeginHorizontal(BaseStyles.toolbar);

                    DrawDetailedViewPopup();
                    GUILayout.FlexibleSpace();

                    cpuModule.DrawOptionsMenuPopup();
                    EditorGUILayout.EndHorizontal();

                    switch (m_DetailedViewType)
                    {
                    case DetailedViewType.Objects:
                        detailedObjectsView.DoGUI(BaseStyles.header, frameDataView, m_TreeView.GetSelection());
                        break;

                    case DetailedViewType.CallersAndCallees:
                        detailedCallsView.DoGUI(BaseStyles.header, frameDataView, m_TreeView.GetSelection());
                        break;
                    }

                    GUILayout.EndVertical();

                    SplitterGUILayout.EndHorizontalSplit();
                }

                HandleKeyboardEvents();
            }
        }
コード例 #7
0
    void OnGUI()
    {
        GUILayout.Space(20);

        m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);


        if (GUILayout.Button("Refresh list of dlls", s_expandWidthOption))
        {
            m_assemblyNames      = MetaFileUtils.GetAllAssembliesWithScripts().Select(a => a.GetName().Name).ToArray();
            m_firstAssemblyIndex = -1;
            //	m_secondAssemblyIndex = -1;
        }

        GUILayout.Label("Total of " + m_assemblyNames.Length + " dlls");


        GUILayout.Space(20);


        //	GUILayout.Label ("Old dll");
        DrawDllRegion(ref m_firstAssemblyIndex, m_assemblyNames);

        //	GUILayout.Space (20);

        //	GUILayout.Label ("New dll");
        //	DrawDllRegion (ref m_secondAssemblyIndex, m_assemblyNames);


        //	GUILayout.Space (20);

        //	if (GUILayout.Button ("Compare 2 dlls", s_expandWidthOption)) {
        //		Compare2Dlls (m_assemblyNames [m_firstAssemblyIndex], m_assemblyNames [m_secondAssemblyIndex]);
        //	}

        GUILayout.Space(30);


        EditorGUILayout.HelpBox("Always make a backup before replacing !", MessageType.Warning, true);


        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Choose source xml file with script ids", s_expandWidthOption))
        {
            string filePath = EditorUtility.OpenFilePanel("Choose xml file with script ids", "", "xml");
            if (!string.IsNullOrEmpty(filePath))
            {
                m_loadedScriptIds     = MetaFileUtils.LoadScriptIdsFromXmlFile(filePath);
                m_chosenSourceXmlFile = System.IO.Path.GetFileName(filePath);
                Debug.LogFormat("Loaded {0} script ids", m_loadedScriptIds.Length);
            }
            EditorGUIUtility.ExitGUI();
        }

        if (!string.IsNullOrEmpty(m_chosenSourceXmlFile))
        {
            GUILayout.Label(m_chosenSourceXmlFile + " - " + m_loadedScriptIds.Length + " script ids");
        }

        GUILayout.EndHorizontal();


        m_testOnly = GUILayout.Toggle(m_testOnly, new GUIContent("Test only", "If checked, assets will not be modified, but you will get output log"));

        if (GUILayout.Button("Replace", s_expandWidthOption))
        {
            this.Replace();
        }


        GUILayout.EndScrollView();

        GUILayout.Space(15);
    }
コード例 #8
0
    private void ShowExecuteArea()
    {
        GUIStyle helpBoxStyle   = EditorStyleUtils.GetHelpBoxStyle();
        GUIStyle textFieldStyle = EditorStyleUtils.GetTextFieldStyle();

        textFieldStyle.fontSize  = 13;
        textFieldStyle.alignment = TextAnchor.MiddleLeft;

        EditorGUILayout.BeginVertical(helpBoxStyle);
        {
            // GUI.color = Color.green;
            EditorGUILayout.BeginHorizontal();
            {
                // GUI.color = Color.green;
                if (GUILayout.Button("Create Excel Class", GUILayout.Height(30)))
                {
                    if (m_SelectedClearFolder)
                    {
                        EditorUtils.DeleteDirectory(m_ExcelClassPath);
                    }

                    int sheetIndex = 0;
                    int count      = m_ExcelSelectedPaths.Count;
                    for (int i = 0; i < count; i++)
                    {
                        string   path           = m_ExcelSelectedPaths[i];
                        string   tableClassName = "";
                        string   tableNoteName  = "";
                        string[] tableName      = Path.GetFileNameWithoutExtension(path).Split('_');
                        tableClassName = tableName[0];
                        if (tableName.Length > 1)
                        {
                            tableNoteName = tableName[1];
                        }

                        Dictionary <string, List <List <ICell> > > sheets = m_ExcelReader.Load(path);
                        foreach (KeyValuePair <string, List <List <ICell> > > keyPair in sheets)
                        {
                            string sheetName = keyPair.Key;
                            EditorUtility.DisplayProgressBar("Info",
                                                             "Create Excel Class : " + (i + 1) + "/" + count + " " + tableClassName + ".cs",
                                                             ((i + 1) / count) * 100);
                            m_ExcelClassCreator.Create(sheetIndex, m_ExcelClassPath, tableClassName, tableNoteName,
                                                       sheetName, keyPair.Value);
                            sheetIndex++;
                        }
                    }

                    if (count > 0)
                    {
                        m_ExcelClassCreator.CreateManager(m_ExcelPaths, m_ExcelSelectedPaths, m_ExcelReader);
                        AssetDatabase.Refresh();
                        EditorUtility.ClearProgressBar();
                        EditorUtility.DisplayDialog("Success", "Create excel class successfully .", "OK");
                        EditorGUIUtility.ExitGUI();
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Worning", "Select some excel files(.xls or .xlsx) , please .",
                                                    "OK");
                    }
                }

                if (GUILayout.Button("Create Excel Data", GUILayout.Height(30)))
                {
                    if (m_SelectedClearFolder)
                    {
                        EditorUtils.DeleteDirectory(m_ExcelDataPath);
                    }

                    Directory.CreateDirectory(m_ExcelDataPath);
                    Assembly assembly = Assembly.Load("Assembly-CSharp");
                    for (int i = 0; i < m_ExcelSelectedPaths.Count; i++)
                    {
                        string   path           = m_ExcelSelectedPaths[i];
                        string[] tableName      = Path.GetFileNameWithoutExtension(path).Split('_');
                        string   tableClassName = tableName[0];
                        Dictionary <string, List <List <ICell> > > sheets = m_ExcelReader.Load(path);
                        foreach (KeyValuePair <string, List <List <ICell> > > keyPair in sheets)
                        {
                            string sheetName = keyPair.Key;

                            Type tableType = assembly.GetType(tableClassName);
                            UnityEngine.Object container = (UnityEngine.Object)Activator.CreateInstance(tableType);
                            FieldInfo          dataList  = tableType.GetField("dataList");

                            Type dataType  = assembly.GetType(tableClassName + "_Data");
                            var  modelList =
                                Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { dataType }));

                            AssetDatabase.CreateAsset(container,
                                                      m_ExcelDataPath.Replace(Application.dataPath, "Assets") + tableClassName + "_" +
                                                      sheetName + ".asset");

                            List <ICell> nameRow = keyPair.Value[0];
                            List <ICell> typeRow = keyPair.Value[1];
                            List <ICell> noteRow = keyPair.Value[2];
                            for (int row = 3; row < keyPair.Value.Count; row++)
                            {
                                UnityEngine.Object data       = (UnityEngine.Object)Activator.CreateInstance(dataType);
                                List <ICell>       contentRow = keyPair.Value[row];
                                for (int column = 0; column < nameRow.Count; column++)
                                {
                                    FieldInfo fieldInfo = dataType.GetField(nameRow[column].StringCellValue);
                                    object    value     = ExcelConvertUtility.GetCellValue(contentRow[column]);
                                    Debug.Log(tableClassName + "_" + sheetName + "_" + row + "_" + column + "_" +
                                              typeRow[column] + "_" + typeRow[column].StringCellValue);
                                    fieldInfo.SetValue(data,
                                                       ExcelConvertUtility.GetConvertType(typeRow[column].StringCellValue, value));
                                }

                                var addMethod = modelList.GetType().GetMethod("Add");
                                addMethod.Invoke(modelList, new object[] { data });
                                dataList.SetValue(container, modelList);

                                data.name = dataType.ToString();
                                AssetDatabase.AddObjectToAsset(data,
                                                               m_ExcelDataPath.Replace(Application.dataPath, "Assets") + tableClassName + "_" +
                                                               sheetName + ".asset");
                            }

                            EditorUtility.SetDirty(container);
                            EditorUtility.DisplayProgressBar("Info",
                                                             "Create Excel Data : " + (i + 1) + "/" + m_ExcelSelectedPaths.Count + " " +
                                                             tableClassName + "_" + sheetName, (i / m_ExcelSelectedPaths.Count) * 100);
                        }
                    }

                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                    EditorUtility.ClearProgressBar();
                    EditorUtility.DisplayDialog("Success", "Create excel data successfully .", "OK");
                    EditorGUIUtility.ExitGUI();
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();
    }
コード例 #9
0
    private void ShowDirectoryArea()
    {
        GUIStyle helpBoxStyle = EditorStyleUtils.GetHelpBoxStyle();

        EditorGUILayout.BeginVertical(helpBoxStyle);
        {
            GUIStyle textFieldStyle = EditorStyleUtils.GetTextFieldStyle();
            textFieldStyle.fontSize  = 13;
            textFieldStyle.alignment = TextAnchor.MiddleLeft;

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Export Class : " + m_ExcelClassPath.Replace(Application.dataPath, "Assets"),
                                           textFieldStyle, GUILayout.Height(30));
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.TextField(m_ExcelOpenPath, textFieldStyle, GUILayout.Height(30));
                // GUI.color = Color.green;
                if (GUILayout.Button("Load Excel Path", GUILayout.Width(120), GUILayout.Height(30)))
                {
                    string path = EditorUtility.OpenFolderPanel("Select Excel Path", "", "");
                    if (path != "")
                    {
                        m_ExcelOpenPath = path + "/";
                        EditorPrefs.SetString(m_ExcelOpenPathKey, m_ExcelOpenPath);
                        m_ExcelSelectedPaths.Clear();
                        m_ExcelPaths.Clear();
                        OpenExcelFolder();
                        EditorGUIUtility.ExitGUI();
                    }
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.TextField(m_ExcelDataPath, textFieldStyle, GUILayout.Height(30));
                // GUI.color = Color.green;
                if (GUILayout.Button("Export Data Path", GUILayout.Width(120), GUILayout.Height(30)))
                {
                    string path = EditorUtility.OpenFolderPanel("Select Data Path", "", "");
                    if (path != "")
                    {
                        m_ExcelDataPath = path + "/";
                        EditorPrefs.SetString(m_ExcelDataPathKey, m_ExcelDataPath);
                    }
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            {
                // GUI.color = Color.green;
                if (m_SelectedClearFolder !=
                    EditorGUILayout.ToggleLeft("Clear Folder", m_SelectedClearFolder, GUILayout.Height(20)))
                {
                    m_SelectedClearFolder = !m_SelectedClearFolder;
                    EditorPrefs.SetBool(m_SelectedClearFolderKey, m_SelectedClearFolder);
                }

                if (GUILayout.Button(EditorGUIUtility.FindTexture("Refresh"), GUILayout.Width(30),
                                     GUILayout.Height(30)))
                {
                    m_ExcelSelectedPaths.Clear();
                    m_ExcelPaths.Clear();
                    OpenExcelFolder();
                    EditorGUIUtility.ExitGUI();
                }

                if (GUILayout.Button("Select All", GUILayout.Width(80), GUILayout.Height(30)))
                {
                    for (int i = 0; i < m_ExcelPaths.Count; i++)
                    {
                        string path = m_ExcelPaths[i];
                        m_ExcelSelectedPaths.Add(path);
                        EditorPrefs.SetBool(path, true);
                    }
                }

                if (GUILayout.Button("Unselect All", GUILayout.Width(80), GUILayout.Height(30)))
                {
                    for (int i = 0; i < m_ExcelPaths.Count; i++)
                    {
                        string path = m_ExcelPaths[i];
                        m_ExcelSelectedPaths.Remove(path);
                        EditorPrefs.SetBool(path, false);
                    }
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();
    }
コード例 #10
0
    void OnGUI()
    {
        if (EditorApplication.isCompiling)
        {
            GUILayout.Label("Compiling...");
            return;
        }

        GUILayout.Label("Lines: " + _sLines.Count);

        GameObject go = (GameObject)EditorGUILayout.ObjectField("Preview Object", _mPreviewObject, typeof(GameObject), true);

        if (go != _mPreviewObject)
        {
            _mPreviewObject = go;
            EditorPrefs.SetInt("PreviewObject", _mPreviewObject.GetInstanceID());
        }

        if (!string.IsNullOrEmpty(_mPath))
        {
            if (GUILayout.Button("Reload"))
            {
                Preview();
                EditorGUIUtility.ExitGUI();
                return;
            }
        }

        if (Selection.activeObject)
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);
            if (!string.IsNullOrEmpty(path) &&
                path.ToLower().EndsWith(".pod"))
            {
                if ((_mPath != path))
                {
                    _mPath = path;
                    Preview();
                    EditorGUIUtility.ExitGUI();
                    return;
                }
            }
        }

        if (!string.IsNullOrEmpty(_mPath))
        {
            GUILayout.Label(_mPath);
            GUILayout.Label("File Size: " + _mFileSize);
        }

        foreach (MeshNode item in _mMeshNodes)
        {
            GUILayout.BeginHorizontal();

            GUILayout.Label("Name:");
            GUILayout.Label(item._mName);

            GUILayout.Label("Stride:");
            GUILayout.Label(item._mStride.ToString());

            GUILayout.Label("VPos:");
            GUILayout.Label(item._mVertexPosition.ToString());

            GUILayout.Label("VCount:");
            GUILayout.Label(item._mVertexCount.ToString());

            GUILayout.Label("FPos:");
            GUILayout.Label(item._mFacePosition.ToString());

            GUILayout.Label("FCount:");
            GUILayout.Label(item._mFaceCount.ToString());

            GUILayout.EndHorizontal();
        }
    }
コード例 #11
0
    void OnGUI()
    {
        Scroll = EditorGUILayout.BeginScrollView(Scroll);

        Editor = GameObject.FindObjectOfType <MotionEditor>();

        if (Editor == null)
        {
            Utility.SetGUIColor(UltiDraw.Black);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();
                Utility.SetGUIColor(UltiDraw.Grey);
                using (new EditorGUILayout.VerticalScope("Box")) {
                    Utility.ResetGUIColor();
                    Utility.SetGUIColor(UltiDraw.Orange);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        EditorGUILayout.LabelField("Exporter");
                    }
                    EditorGUILayout.LabelField("No Motion Editor found in scene.");
                }
            }
        }
        else
        {
            Utility.SetGUIColor(UltiDraw.Black);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();

                Utility.SetGUIColor(UltiDraw.Grey);
                using (new EditorGUILayout.VerticalScope("Box")) {
                    Utility.ResetGUIColor();

                    Utility.SetGUIColor(UltiDraw.Orange);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        EditorGUILayout.LabelField("Exporter");
                    }

                    Framerate      = EditorGUILayout.FloatField("Framerate", Framerate);
                    BatchSize      = Mathf.Max(1, EditorGUILayout.IntField("Batch Size", BatchSize));
                    WriteMirror    = EditorGUILayout.Toggle("Write Mirror", WriteMirror);
                    LoadActiveOnly = EditorGUILayout.Toggle("Load Active Only", LoadActiveOnly);

                    Utility.SetGUIColor(UltiDraw.White);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        EditorGUILayout.LabelField("Export Path: " + GetExportPath());
                    }

                    Utility.SetGUIColor(UltiDraw.LightGrey);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        Utility.SetGUIColor(UltiDraw.Cyan);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            EditorGUILayout.LabelField("Files" + " [" + Files.Count + "]");
                        }
                        ShowFiles = EditorGUILayout.Toggle("Show Files", ShowFiles);
                        if (Files.Count == 0)
                        {
                            EditorGUILayout.LabelField("No files found.");
                        }
                        else
                        {
                            if (ShowFiles)
                            {
                                EditorGUILayout.BeginHorizontal();
                                if (Utility.GUIButton("Export All", UltiDraw.DarkGrey, UltiDraw.White))
                                {
                                    for (int i = 0; i < Export.Count; i++)
                                    {
                                        if (Files[i].Export)
                                        {
                                            Export[i] = Files[i].Export;
                                        }
                                    }
                                }
                                if (Utility.GUIButton("Export None", UltiDraw.DarkGrey, UltiDraw.White))
                                {
                                    for (int i = 0; i < Export.Count; i++)
                                    {
                                        Export[i] = false;
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                                EditorGUILayout.BeginHorizontal();
                                Start = EditorGUILayout.IntField("Start", Start);
                                End   = EditorGUILayout.IntField("End", End);
                                if (Utility.GUIButton("Toggle", UltiDraw.DarkGrey, UltiDraw.White))
                                {
                                    for (int i = Start - 1; i <= End - 1; i++)
                                    {
                                        if (Files[i].Export)
                                        {
                                            Export[i] = !Export[i];
                                        }
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                                for (int i = 0; i < Files.Count; i++)
                                {
                                    Utility.SetGUIColor(Index == i ? UltiDraw.Cyan : Export[i] ? UltiDraw.Gold : UltiDraw.White);
                                    using (new EditorGUILayout.VerticalScope("Box")) {
                                        Utility.ResetGUIColor();
                                        EditorGUILayout.BeginHorizontal();
                                        EditorGUILayout.LabelField((i + 1) + " - " + Files[i].GetName(), GUILayout.Width(200f));
                                        if (Files[i].Export)
                                        {
                                            EditorGUILayout.BeginVertical();
                                            if (Files[i].Export)
                                            {
                                                string info = " Scene - ";
                                                if (Files[i].Symmetric)
                                                {
                                                    info += "[Default / Mirror]";
                                                }
                                                else
                                                {
                                                    info += "[Default]";
                                                }
                                                EditorGUILayout.LabelField(info, GUILayout.Width(200f));
                                            }
                                            EditorGUILayout.EndVertical();
                                            GUILayout.FlexibleSpace();
                                            if (Utility.GUIButton("O", Export[i] ? UltiDraw.DarkGreen : UltiDraw.DarkRed, UltiDraw.White, 50f))
                                            {
                                                Export[i] = !Export[i];
                                            }
                                        }
                                        EditorGUILayout.EndHorizontal();
                                    }
                                }
                            }
                        }
                    }

                    Utility.SetGUIColor(UltiDraw.LightGrey);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        Utility.SetGUIColor(UltiDraw.Cyan);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            EditorGUILayout.LabelField("Actions" + " [" + Actions.Count + "]");
                        }
                        if (Actions.Count == 0)
                        {
                            EditorGUILayout.LabelField("No actions found.");
                        }
                        else
                        {
                            for (int i = 0; i < Actions.Count; i++)
                            {
                                Utility.SetGUIColor(UltiDraw.Grey);
                                using (new EditorGUILayout.VerticalScope("Box")) {
                                    Utility.ResetGUIColor();
                                    EditorGUILayout.BeginHorizontal();
                                    EditorGUILayout.LabelField("Group " + (i + 1));
                                    if (Utility.GUIButton("X", UltiDraw.DarkRed, UltiDraw.White, 20f, 20f))
                                    {
                                        Actions.RemoveAt(i);
                                        EditorGUIUtility.ExitGUI();
                                    }
                                    EditorGUILayout.EndHorizontal();
                                    for (int j = 0; j < Actions[i].Labels.Length; j++)
                                    {
                                        Actions[i].Labels[j] = EditorGUILayout.TextField(Actions[i].Labels[j]);
                                    }
                                    EditorGUILayout.BeginHorizontal();
                                    if (Utility.GUIButton("+", UltiDraw.DarkGrey, UltiDraw.White))
                                    {
                                        ArrayExtensions.Expand(ref Actions[i].Labels);
                                    }
                                    if (Utility.GUIButton("-", UltiDraw.DarkGrey, UltiDraw.White))
                                    {
                                        ArrayExtensions.Shrink(ref Actions[i].Labels);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }
                    }

                    Utility.SetGUIColor(UltiDraw.LightGrey);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        Utility.SetGUIColor(UltiDraw.Cyan);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            EditorGUILayout.LabelField("Styles" + " [" + Styles.Count + "]");
                        }
                        if (Styles.Count == 0)
                        {
                            EditorGUILayout.LabelField("No styles found.");
                        }
                        else
                        {
                            for (int i = 0; i < Styles.Count; i++)
                            {
                                Utility.SetGUIColor(UltiDraw.Grey);
                                using (new EditorGUILayout.VerticalScope("Box")) {
                                    Utility.ResetGUIColor();
                                    EditorGUILayout.BeginHorizontal();
                                    EditorGUILayout.LabelField("Group " + (i + 1));
                                    if (Utility.GUIButton("X", UltiDraw.DarkRed, UltiDraw.White, 20f, 20f))
                                    {
                                        Styles.RemoveAt(i);
                                        EditorGUIUtility.ExitGUI();
                                    }
                                    EditorGUILayout.EndHorizontal();
                                    for (int j = 0; j < Styles[i].Labels.Length; j++)
                                    {
                                        Styles[i].Labels[j] = EditorGUILayout.TextField(Styles[i].Labels[j]);
                                    }
                                    EditorGUILayout.BeginHorizontal();
                                    if (Utility.GUIButton("+", UltiDraw.DarkGrey, UltiDraw.White))
                                    {
                                        ArrayExtensions.Expand(ref Styles[i].Labels);
                                    }
                                    if (Utility.GUIButton("-", UltiDraw.DarkGrey, UltiDraw.White))
                                    {
                                        ArrayExtensions.Shrink(ref Styles[i].Labels);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }
                    }

                    if (!Exporting)
                    {
                        if (Utility.GUIButton("Reload", UltiDraw.DarkGrey, UltiDraw.White))
                        {
                            Load();
                        }
                        if (Utility.GUIButton("Export Data", UltiDraw.DarkGrey, UltiDraw.White))
                        {
                            this.StartCoroutine(ExportDataSIGGRAPHAsia());
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("File: " + Editor.GetData().GetName());

                        EditorGUI.DrawRect(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, Progress * EditorGUILayout.GetControlRect().width, 25f), UltiDraw.Green.Transparent(0.75f));

                        EditorGUILayout.LabelField("Frames Per Second: " + Performance.ToString("F3"));

                        if (Utility.GUIButton("Stop", UltiDraw.DarkRed, UltiDraw.White))
                        {
                            Exporting = false;
                        }
                    }
                }
            }
        }

        EditorGUILayout.EndScrollView();
    }
コード例 #12
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.PropertyField(hostTransform);
            EditorGUILayout.PropertyField(manipulationType);
            EditorGUILayout.PropertyField(allowFarManipulation);

            var handedness = (ManipulationHandFlags)manipulationType.intValue;

            EditorGUILayout.Space();
            GUIStyle  style         = EditorStyles.foldout;
            FontStyle previousStyle = style.fontStyle;

            style.fontStyle  = FontStyle.Bold;
            oneHandedFoldout = EditorGUILayout.Foldout(oneHandedFoldout, "One Handed Manipulation", true);

            if (oneHandedFoldout)
            {
                if (handedness.HasFlag(ManipulationHandFlags.OneHanded))
                {
                    EditorGUILayout.PropertyField(oneHandRotationModeNear);
                    EditorGUILayout.PropertyField(oneHandRotationModeFar);
                }
                else
                {
                    EditorGUILayout.HelpBox("One handed manipulation disabled. If you wish to enable one handed manipulation select it as a Manipulation Type above.", MessageType.Info);
                }
            }

            EditorGUILayout.Space();
            twoHandedFoldout = EditorGUILayout.Foldout(twoHandedFoldout, "Two Handed Manipulation", true);

            if (twoHandedFoldout)
            {
                if (handedness.HasFlag(ManipulationHandFlags.TwoHanded))
                {
                    EditorGUILayout.PropertyField(twoHandedManipulationType);
                }
                else
                {
                    EditorGUILayout.HelpBox("Two handed manipulation disabled. If you wish to enable two handed manipulation select it as a Manipulation Type above.", MessageType.Info);
                }
            }

            var mh = (ObjectManipulator)target;
            var rb = mh.HostTransform.GetComponent <Rigidbody>();

            EditorGUILayout.Space();
            constraintsFoldout = EditorGUILayout.Foldout(constraintsFoldout, "Constraints", true);

            if (constraintsFoldout)
            {
                if (EditorGUILayout.DropdownButton(new GUIContent("Add Constraint"), FocusType.Keyboard))
                {
                    // create the menu and add items to it
                    GenericMenu menu = new GenericMenu();

                    var type  = typeof(TransformConstraint);
                    var types = AppDomain.CurrentDomain.GetAssemblies()
                                .SelectMany(s => s.GetLoadableTypes())
                                .Where(p => type.IsAssignableFrom(p) && !p.IsAbstract);

                    foreach (var derivedType in types)
                    {
                        menu.AddItem(new GUIContent(derivedType.Name), false, t => mh.gameObject.AddComponent((Type)t), derivedType);
                    }

                    menu.ShowAsContext();
                }

                var constraints = mh.GetComponents <TransformConstraint>();

                foreach (var constraint in constraints)
                {
                    EditorGUILayout.BeginHorizontal();
                    string constraintName = constraint.GetType().Name;
                    EditorGUILayout.LabelField(constraintName);
                    if (GUILayout.Button("Go to component"))
                    {
                        Highlighter.Highlight("Inspector", $"{ObjectNames.NicifyVariableName(constraintName)} (Script)");
                        EditorGUIUtility.ExitGUI();
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.Space();
            physicsFoldout = EditorGUILayout.Foldout(physicsFoldout, "Physics", true);

            if (physicsFoldout)
            {
                if (rb != null)
                {
                    EditorGUILayout.PropertyField(releaseBehavior);
                    EditorGUILayout.PropertyField(useForcesForNearManipulation);
                }
                else
                {
                    EditorGUILayout.HelpBox("Physics options disabled. If you wish to enable physics options, add a Rigidbody component to this object.", MessageType.Info);
                }
            }

            EditorGUILayout.Space();
            smoothingFoldout = EditorGUILayout.Foldout(smoothingFoldout, "Smoothing", true);

            if (smoothingFoldout)
            {
                EditorGUILayout.PropertyField(smoothingFar);
                EditorGUILayout.PropertyField(smoothingNear);
                EditorGUILayout.PropertyField(moveLerpTime);
                EditorGUILayout.PropertyField(rotateLerpTime);
                EditorGUILayout.PropertyField(scaleLerpTime);
            }

            EditorGUILayout.Space();
            elasticsFoldout = EditorGUILayout.Foldout(elasticsFoldout, "Elastics", true);

            if (elasticsFoldout)
            {
                // This two-way enum cast is required because EnumFlagsField does not play nicely with
                // SerializedProperties and custom enum flags.
                var newElasticTypesValue = EditorGUILayout.EnumFlagsField("Manipulation types using elastic feedback: ", (TransformFlags)elasticTypes.intValue);
                elasticTypes.intValue = (int)(TransformFlags)newElasticTypesValue;

                // If the particular elastic type is requested, we offer the user the ability
                // to configure the elastic system.
                TransformFlags currentFlags = (TransformFlags)elasticTypes.intValue;

                translationElasticFoldout = DrawElasticConfiguration <ElasticConfiguration>(
                    "Translation Elastic",
                    translationElasticFoldout,
                    translationElasticConfigurationObject,
                    translationElasticExtent,
                    TransformFlags.Move,
                    currentFlags);

                rotationElasticFoldout = DrawElasticConfiguration <ElasticConfiguration>(
                    "Rotation Elastic",
                    rotationElasticFoldout,
                    rotationElasticConfigurationObject,
                    rotationElasticExtent,
                    TransformFlags.Rotate,
                    currentFlags);

                scaleElasticFoldout = DrawElasticConfiguration <ElasticConfiguration>(
                    "Scale Elastic",
                    scaleElasticFoldout,
                    scaleElasticConfigurationObject,
                    scaleElasticExtent,
                    TransformFlags.Scale,
                    currentFlags);
            }

            EditorGUILayout.Space();
            eventsFoldout = EditorGUILayout.Foldout(eventsFoldout, "Manipulation Events", true);

            if (eventsFoldout)
            {
                EditorGUILayout.PropertyField(onManipulationStarted);
                EditorGUILayout.PropertyField(onManipulationEnded);
                EditorGUILayout.PropertyField(onHoverEntered);
                EditorGUILayout.PropertyField(onHoverExited);
            }

            // reset foldouts style
            style.fontStyle = previousStyle;

            serializedObject.ApplyModifiedProperties();
        }
コード例 #13
0
        public override void OnInspectorGUI()
        {
#if UNITY_5_6_OR_NEWER
            serializedObject.UpdateIfRequiredOrScript();
#else
            serializedObject.UpdateIfDirtyOrScript();
#endif

            if (titleLabelStyle == null)
            {
                titleLabelStyle = new GUIStyle(EditorStyles.label);
            }
            titleLabelStyle.normal.textColor = titleColor;
            titleLabelStyle.fontStyle        = FontStyle.Bold;


            EditorGUILayout.Separator();

            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.BeginHorizontal(blackBack);
            GUILayout.Label(_headerTexture, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Hexasphere Settings", titleLabelStyle);
            if (GUILayout.Button("Help", GUILayout.Width(40)))
            {
                if (!EditorUtility.DisplayDialog("Hexasphere Grid System", "To learn more about a property in this inspector move the mouse over the label for a quick description (tooltip).\n\nPlease check README file in the root of the asset for details and contact support.\n\nIf you like Hexasphere Grid System, please rate it on the Asset Store. For feedback and suggestions visit our support forum on kronnect.com.", "Close", "Visit Support Forum"))
                {
                    Application.OpenURL("http://kronnect.com/taptapgo");
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.PropertyField(style, new GUIContent("Style", "Style for the hexasphere."));

            EditorGUILayout.BeginHorizontal();
            divisions = EditorGUILayout.IntSlider(new GUIContent("Divisions", "Number of divisions during the generation of the hexasphere."), divisions, 2, 200);
            if (GUILayout.Button("Redraw"))
            {
                numDivisions.intValue = divisions;
            }
            EditorGUILayout.EndHorizontal();


            if (hexa != null)
            {
                EditorGUILayout.LabelField("Tile Count", hexa.tiles.Length.ToString());
            }

            GUI.enabled = style.intValue == (int)STYLE.ShadedWireframe || style.intValue == (int)STYLE.Wireframe;
            EditorGUILayout.PropertyField(smartEdges, new GUIContent("Smart Edges", "Only renders edges between two tiles with different materials."));
            GUI.enabled = true;
            EditorGUILayout.PropertyField(transparent, new GUIContent("Transparent", "Enable transparency support."));
            if (transparent.boolValue)
            {
                EditorGUILayout.PropertyField(transparencyTiles, new GUIContent("   Tiles Alpha", "Global transparency for tiles."));
                EditorGUILayout.PropertyField(transparencyCull, new GUIContent("   Cull Back Tiles", "Prevents rendering of back side tiles."));
            }
            EditorGUILayout.PropertyField(invertedMode, new GUIContent("Inverted Mode", "Renders the hexasphere inwards, making the camera stay at center of the sphere."));
            if (invertedMode.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(extruded, new GUIContent("Extruded", "Enable to allow extrusion of tiles."));
            if (extruded.boolValue)
            {
                EditorGUILayout.PropertyField(extrudeMultiplier, new GUIContent("   Multiplier", "Global extrusion multiplier."));
                EditorGUILayout.PropertyField(gradientIntensity, new GUIContent("   Gradient Intensity", "Intensity of the color gradient effect."));
                EditorGUILayout.PropertyField(raycast3D, new GUIContent("   Raycast 3D", "Improves precision of tile selection when extrusion is enabled."));
            }
            GUI.enabled = true;
            EditorGUILayout.PropertyField(wireframeColor, new GUIContent("Wireframe Color", "Color for the wireframe."));
            if (extruded.boolValue)
            {
                EditorGUILayout.PropertyField(wireframeColorFromTile, new GUIContent("   Color From Tile", "Use tile color as a base color for the wireframe."));
                EditorGUILayout.PropertyField(wireframeIntensity, new GUIContent("   Intensity", "Darkens or lightens the wireframe."));
            }

            EditorGUILayout.PropertyField(defaultShadedColor, new GUIContent("Default Tile Color", "Default color for the tiles that are not colored or textured by user."));
            EditorGUILayout.PropertyField(tileTintColor, new GUIContent("Tile Tint Color", "Tint color applied to all tiles, either colored or non-colored tiles."));
            EditorGUILayout.PropertyField(lighting, new GUIContent("Use Lighting", "If the hexasphere geometry can cast shadows over itself or other geometry, and also be influenced by the directional light."));
            EditorGUILayout.PropertyField(ambientColor, new GUIContent("Ambient Color", "Ambient color is added to the final tile color."));
            EditorGUILayout.PropertyField(receiveShadows, new GUIContent("Receive Shadows", "If hexasphere can receive shadows."));
            EditorGUILayout.PropertyField(tileTextureSize, new GUIContent("Tile Texture Size", "Textures assigned to tiles will be rescaled to this size if different. Note that textures should be marked as readable."));
            EditorGUILayout.PropertyField(rotationShift, new GUIContent("Rotation Shift", "Applies an internal rotation to the generated vertices. Let's you control where the pentagons will be located."));
            EditorGUILayout.PropertyField(vrEnabled, new GUIContent("VR Enabled", "Uses VR-compatible raycasting."));
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Interaction Settings", titleLabelStyle);
            EditorGUILayout.PropertyField(highlightEnabled, new GUIContent("Enable Highlight", "Enables or disables selection of tiles."));
            EditorGUILayout.PropertyField(highlightColor, new GUIContent("Highlight Color", "Main tint color for the highlighted tile."));
            EditorGUILayout.PropertyField(highlightSpeed, new GUIContent("   Highlight Speed", "Speed for the flashing animation."));
            EditorGUILayout.PropertyField(rotationEnabled, new GUIContent("Enable Rotation", "Enables or disables rotation of hexasphere by user drag."));
            EditorGUILayout.PropertyField(rotationSpeed, new GUIContent("   Rotation Speed", "Speed for the rotation."));
            EditorGUILayout.PropertyField(rotationAxisAllowed, new GUIContent("   Rotation Axis", "Allowed rotation axis."));
            if (rotationAxisAllowed.intValue == (int)ROTATION_AXIS_ALLOWED.STRAIGHT)
            {
                EditorGUILayout.PropertyField(rotationAxisVerticalThreshold, new GUIContent("   Min Pole Distance", "Allowed minimum distance to North or South Pole."));
            }
            EditorGUILayout.PropertyField(rightButtonDrag, new GUIContent("Right Button Drag", "If set to true, user can hold and drag the hexasphere using the right mouse button."));
            if (rightButtonDrag.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(rightClickRotates, new GUIContent("Right Click Rotates", "Enables or disables rotation of hexasphere by pressing mouse right button."));
            EditorGUILayout.PropertyField(reverseDragDirection, new GUIContent("Reverse Drag Direction", "Reverses the direction the drag rotates the planet"));
            EditorGUILayout.PropertyField(rightClickRotatingClockwise, new GUIContent("   Clockwise Rotation", "Direction of the rotation."));
            GUI.enabled = true;
            EditorGUILayout.PropertyField(zoomEnabled, new GUIContent("Enable Zoom", "Enables or disables zoom of hexasphere by using mouse wheel or pinch in/out."));
            EditorGUILayout.PropertyField(zoomSpeed, new GUIContent("   Zoom Speed", "Speed for the zoom in/out."));
            EditorGUILayout.PropertyField(zoomDamping, new GUIContent("   Zoom Damping", "Speed for decelerating zoom once wheel has been released."));
            EditorGUILayout.PropertyField(zoomMinDistance, new GUIContent("   Min Distance", "Minimum distance to the hexasphere when zooming in. This is a factor of the radius."));
            EditorGUILayout.PropertyField(zoomMaxDistance, new GUIContent("   Max Distance", "Maximum distance to the hexasphere when zooming out. This is a factor of the radius."));
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Path Finding Settings", titleLabelStyle);
            EditorGUILayout.PropertyField(pathFindingFormula, new GUIContent("Estimation Method", "The estimation method used for getting the path between two tiles."));
            EditorGUILayout.PropertyField(pathFindingSearchLimit, new GUIContent("Search Limit", "Maximum path length."));
            EditorGUILayout.PropertyField(pathFindingUseExtrusion, new GUIContent("Use Extrusion", "If path-finding should use tiles' extrusion (altitude) value as part of their crossing cost."));
            if (pathFindingUseExtrusion.boolValue)
            {
                EditorGUILayout.PropertyField(pathFindingExtrusionWeight, new GUIContent("   Extrusion Weight", "Weight for the extrusion of each tile. The extrusion value (0..1) is multiplied by this value then added to the tile crossing cost."));
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Tools", titleLabelStyle);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Export Wireframe"))
            {
                if (EditorUtility.DisplayDialog("Create Asset", "Current hexasphere wireframe mesh will be exported to project root.", "Ok", "Cancel"))
                {
                    Transform t = hexa.transform.Find("WireFrame/Wire");
                    if (t != null)
                    {
                        MeshFilter mf = t.GetComponent <MeshFilter> ();
                        if (mf != null)
                        {
                            SaveMeshAsset(mf.sharedMesh);
                        }
                    }
                }
            }
            if (GUILayout.Button("Export Model"))
            {
                if (EditorUtility.DisplayDialog("Create Asset", "Current hexasphere shaded model will be exported to project root.", "Ok", "Cancel"))
                {
                    Transform t = hexa.transform.Find("ShadedFrame/Shade");
                    if (t != null)
                    {
                        MeshFilter mf = t.GetComponent <MeshFilter> ();
                        if (mf != null)
                        {
                            SaveMeshAsset(mf.sharedMesh);
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            if (!Application.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Grid Editor", titleLabelStyle);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Export Tiles"))
                {
                    if (EditorUtility.DisplayDialog("Export Grid Settings", "This option will add a Hexasphere Config component to this game object with current tile settings. You can restore this configuration just enabling this new component.", "Ok", "Cancel"))
                    {
                        CreatePlaceholder();
                    }
                }
                if (GUILayout.Button("Reset"))
                {
                    if (EditorUtility.DisplayDialog("Reset Grid", "Reset tiles to their default values?", "Ok", "Cancel"))
                    {
                        ResetTiles();
                        GUIUtility.ExitGUI();
                        return;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(enableGridEditor, new GUIContent("Enable Editor", "Enables grid editing options in Scene View"));
                EditorGUILayout.EndHorizontal();

                if (enableGridEditor.boolValue)
                {
                    int selectedCount = tileSelectedIndices.Count;
                    if (targets.Length > 1)
                    {
                        GUILayout.Label("Grid Editor only works with one hexasphere at a time.");
                    }
                    else if (selectedCount == 0)
                    {
                        GUILayout.Label("Click on a tile in Scene View to edit its properties\n(hold Control to select multiple tiles).");
                    }
                    else
                    {
                        // Check that all selected tiles are within range
                        for (int k = 0; k < selectedCount; k++)
                        {
                            if (tileSelectedIndices [k] < 0 || tileSelectedIndices [k] >= hexa.tiles.Length)
                            {
                                tileSelectedIndices.Clear();
                                EditorGUIUtility.ExitGUI();
                                return;
                            }
                        }
                        int tileSelectedIndex = tileSelectedIndices [0];

                        EditorGUILayout.BeginHorizontal();
                        if (selectedCount == 1)
                        {
                            GUILayout.Label("Selected Cell", GUILayout.Width(120));
                            GUILayout.Label(tileSelectedIndex.ToString(), GUILayout.Width(120));
                        }
                        else
                        {
                            GUILayout.Label("Selected Cells", GUILayout.Width(120));
                            sb.Length = 0;
                            for (int k = 0; k < selectedCount; k++)
                            {
                                if (k > 0)
                                {
                                    sb.Append(", ");
                                }
                                sb.Append(tileSelectedIndices [k].ToString());
                            }
                            GUILayout.Label(sb.ToString());
                        }
                        EditorGUILayout.EndHorizontal();
                        Tile selectedTile = hexa.tiles [tileSelectedIndex];

                        if (selectedCount == 1)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   String Tag", GUILayout.Width(120));
                            tileTag = EditorGUILayout.TextField(tileTag);
                            if (tileTag == selectedTile.tag || (string.IsNullOrEmpty(tileTag) && string.IsNullOrEmpty(selectedTile.tag)))
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button("Set Tag", GUILayout.Width(60)))
                            {
                                hexa.SetTileTag(tileSelectedIndex, tileTag);
                            }
                            GUI.enabled = true;
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Integer Tag", GUILayout.Width(120));
                            tileTagInt = EditorGUILayout.IntField(tileTagInt, GUILayout.Width(60));
                            if (tileTagInt == selectedTile.tagInt)
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button("Set Tag", GUILayout.Width(60)))
                            {
                                hexa.SetTileTag(tileSelectedIndex, tileTagInt);
                            }
                            GUI.enabled = true;
                            EditorGUILayout.EndHorizontal();
                        }

                        bool needsRedraw = false;

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Color", GUILayout.Width(120));
                        tileColor = EditorGUILayout.ColorField(tileColor, GUILayout.Width(40));
                        GUILayout.Label("  Texture", GUILayout.Width(60));
                        tileTextureIndex = EditorGUILayout.IntField(tileTextureIndex, GUILayout.Width(40));
                        if (hexa.GetTileColor(tileSelectedIndex, true) == tileColor && hexa.GetTileTextureIndex(tileSelectedIndex) == tileTextureIndex)
                        {
                            GUI.enabled = false;
                        }
                        if (GUILayout.Button(new GUIContent("Set", "Press ALT+S to quick set"), GUILayout.Width(50)))
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                hexa.SetTileTexture(tileSelectedIndices [k], tileTextureIndex, tileColor, false);
                            }
                            needsRedraw = true;
                        }
                        GUI.enabled = true;
                        if (GUILayout.Button(new GUIContent("Clear", "Press ALT+C to quick clear"), GUILayout.Width(50)))
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                hexa.ClearTile(tileSelectedIndices [k]);
                            }
                            needsRedraw = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        if (needsRedraw)
                        {
                            RefreshGrid();
                            GUIUtility.ExitGUI();
                            return;
                        }
                    }

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Textures", GUILayout.Width(120));
                    EditorGUILayout.EndHorizontal();

                    if (toggleButtonStyleNormal == null)
                    {
                        toggleButtonStyleNormal  = "Button";
                        toggleButtonStyleToggled = new GUIStyle(toggleButtonStyleNormal);
                        toggleButtonStyleToggled.normal.background = toggleButtonStyleToggled.active.background;
                    }

                    int textureMax = hexa.textures.Length - 1;
                    while (textureMax >= 1 && hexa.textures [textureMax] == null)
                    {
                        textureMax--;
                    }
                    textureMax++;
                    if (textureMax >= hexa.textures.Length)
                    {
                        textureMax = hexa.textures.Length - 1;
                    }

                    for (int k = 1; k <= textureMax; k++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("  " + k.ToString(), GUILayout.Width(40));
                        hexa.textures [k] = (Texture2D)EditorGUILayout.ObjectField(hexa.textures [k], typeof(Texture2D), false);
                        if (hexa.textures [k] != null)
                        {
                            if (GUILayout.Button(new GUIContent("T", "Texture mode - if enabled, you can paint several tiles just clicking over them."), textureMode == k ? toggleButtonStyleToggled : toggleButtonStyleNormal, GUILayout.Width(20)))
                            {
                                textureMode = textureMode == k ? 0 : k;
                            }
                            if (GUILayout.Button(new GUIContent("X", "Remove texture"), GUILayout.Width(20)))
                            {
                                if (EditorUtility.DisplayDialog("Remove texture", "Are you sure you want to remove this texture?", "Yes", "No"))
                                {
                                    hexa.textures [k] = null;
                                    GUIUtility.ExitGUI();
                                    return;
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            EditorGUILayout.Separator();



            if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ExecuteCommand &&
                                                               Event.current.commandName == "UndoRedoPerformed"))
            {
                foreach (Hexasphere hex in targets)
                {
                    hex.UpdateMaterialProperties();
                }
                HideEditorMesh();
                SceneView.RepaintAll();
            }
        }
コード例 #14
0
        public override void OnInspectorGUI()
        {
            EmptyMarker o = (EmptyMarker)target;

            EditorGUI.BeginChangeCheck();
            var newMf = (MeshFilter)EditorGUILayout.ObjectField("MeshFilter", o.mf, typeof(MeshFilter), true);

            if (EditorGUI.EndChangeCheck())
            {
                o.mf = newMf;
                EUtil.SetDirty(o);
            }

            EUtil.PushGUIEnable(o.mf != null);
            {
                EditorGUI.BeginChangeCheck();
                var newMesh = (Mesh)EditorGUILayout.ObjectField("Mesh", o.mesh, typeof(Mesh), false);
                if (EditorGUI.EndChangeCheck())
                {
                    o.mesh = newMesh;
                    EUtil.SetDirty(o);
                }

                EditorGUI.BeginChangeCheck();
                var newMat = (Material)EditorGUILayout.ObjectField("Material", o.material, typeof(Material), false);
                if (EditorGUI.EndChangeCheck())
                {
                    o.material = newMat;
                    EUtil.SetDirty(o);
                }

                EditorGUI.BeginChangeCheck();
                var newSelMat = (Material)EditorGUILayout.ObjectField("Selected Material", o.selectedMaterial, typeof(Material), false);
                if (EditorGUI.EndChangeCheck())
                {
                    o.selectedMaterial = newSelMat;
                    EUtil.SetDirty(o);
                }
            }
            EUtil.PopGUIEnable();

            EditorGUI.BeginChangeCheck();
            o.jumpTo = (Transform)EditorGUILayout.ObjectField("Jump To", o.jumpTo, typeof(Transform), true);
            if (EditorGUI.EndChangeCheck())
            {
                EUtil.SetDirty(o);
            }

            // create "mesh" child object to hold marker
            EditorGUILayout.BeginHorizontal();
            {
                Rect rc = GUILayoutUtility.GetRect(new GUIContent("Presets"), GUI.skin.button);
                if (GUI.Button(rc, new GUIContent("Presets", "select presets marker")))
                {
                    PopupWindow.Show(rc, new EmptyMarkerPresetsPopup(o));
                }

                if (GUILayout.Button(new GUIContent("Delete", "delete marker")))
                {
                    if (o.mf != null)
                    {
                        MUndo.DestroyObj(o.mf.gameObject);
                    }

                    MUndo.DestroyObj(o);

                    EditorGUIUtility.ExitGUI();
                }

                if (o.jumpTo != null)
                {
                    if (GUILayout.Button(new GUIContent("Target", "jump to the target transform")))
                    {
                        Selection.activeTransform = o.jumpTo;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #15
0
        static void DoRepositoryField(
            Action <RepositoryCreationData> createRepositoryAction,
            EditorWindow parentWindow,
            string defaultServer,
            ref CreateWorkspaceViewState state)
        {
            EditorGUILayout.BeginHorizontal();

            DoLabel("Repository name");

            state.RepositoryName = DoTextField(
                state.RepositoryName,
                !state.ProgressData.IsOperationRunning,
                LABEL_WIDTH,
                TEXTBOX_WIDTH - BROWSE_BUTTON_WIDTH);

            float browseButtonX =
                LABEL_WIDTH + TEXTBOX_WIDTH + BUTTON_MARGIN -
                BROWSE_BUTTON_WIDTH;
            float browseButtonWidth =
                BROWSE_BUTTON_WIDTH - BUTTON_MARGIN;

            if (DoButton(
                    "...",
                    !state.ProgressData.IsOperationRunning,
                    browseButtonX,
                    browseButtonWidth))
            {
                DoBrowseRepositoryButton(
                    parentWindow,
                    defaultServer,
                    ref state);
                EditorGUIUtility.ExitGUI();
            }

            float newButtonX =
                LABEL_WIDTH + TEXTBOX_WIDTH + BUTTON_MARGIN;
            float newButtonWidth =
                NEW_BUTTON_WIDTH - BUTTON_MARGIN;

            if (DoButton(
                    "New ...",
                    !state.ProgressData.IsOperationRunning,
                    newButtonX, newButtonWidth))
            {
                DoNewRepositoryButton(
                    createRepositoryAction,
                    parentWindow,
                    state.RepositoryName,
                    defaultServer);
                EditorGUIUtility.ExitGUI();
            }

            ValidationResult validationResult = ValidateRepositoryName(
                state.RepositoryName);

            if (!validationResult.IsValid)
            {
                DoWarningLabel(validationResult.ErrorMessage,
                               LABEL_WIDTH + TEXTBOX_WIDTH + NEW_BUTTON_WIDTH + LABEL_MARGIN);
            }

            EditorGUILayout.EndHorizontal();
        }
コード例 #16
0
        void DrawTopRowButtons()
        {
            EditorGUILayout.BeginVertical();

            Rect  space = EditorGUILayout.BeginHorizontal();
            float width = EditorGUIUtility.currentViewWidth;

            const int w = 32;
            const int h = 32;

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("New");
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("4", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(4, 4);
            }
            if (GUILayout.Button("8", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(8, 8);
            }
            if (GUILayout.Button("16", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(16, 16);
            }
            if (GUILayout.Button("32", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(32, 32);
            }
            if (GUILayout.Button("64", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(64, 64);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Texture");
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            texture = (Texture2D)EditorGUILayout.ObjectField(GUIContent.none, texture, typeof(Texture2D), false, GUILayout.Width(w), GUILayout.Height(h));
            if (EditorGUI.EndChangeCheck())
            {
                sprite = null;
                LoadFile();
            }
            GUI.enabled = sprite == null;
            if (GUILayout.Button(icons[ICON_SAVE_TEXTURE], GUILayout.Width(w), GUILayout.Height(h)))
            {
                SaveTexture(TextureImporterType.Default);
                EditorGUIUtility.ExitGUI();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Sprite");
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            sprite = (Sprite)EditorGUILayout.ObjectField(GUIContent.none, sprite, typeof(Sprite), false, GUILayout.Width(w), GUILayout.Height(h));
            if (EditorGUI.EndChangeCheck())
            {
                texture = null;
                LoadFile();
            }
            GUI.enabled = texture == null;
            if (GUILayout.Button(icons[ICON_SAVE_SPRITE], GUILayout.Width(w), GUILayout.Height(h)))
            {
                SaveTexture(TextureImporterType.Sprite);
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            Color prevContentColor = GUI.contentColor;

            if (!EditorGUIUtility.isProSkin)
            {
                GUI.contentColor = Color.black;
            }
            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Undo / Redo");
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(icons[ICON_UNDO], GUILayout.Width(w), GUILayout.Height(h)))
            {
                EditorApplication.delayCall += () => Undo.PerformUndo();
            }
            if (GUILayout.Button(icons[ICON_REDO], GUILayout.Width(w), GUILayout.Height(h)))
            {
                EditorApplication.delayCall += () => Undo.PerformRedo();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Brush Color");
            space         = EditorGUILayout.BeginHorizontal();
            space.xMin   += 5;
            space.yMin   += 5;
            space.height -= 5;
            space.width   = space.height;
            if (GUILayout.Button(icons[ICON_COLOR_PICKER], GUILayout.Width(w), GUILayout.Height(h)))
            {
                CSWindow.ShowWindow(1);
            }
            GUI.DrawTexture(space, brushColorTexture, ScaleMode.StretchToFill);
            if (GUILayout.Button(icons[ICON_TRANSPARENT], GUILayout.Width(w), GUILayout.Height(h)))
            {
                brushColor = new Color(0, 0, 0, 0);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            int mw = 32 * brushWidths.Length;

            GUILayout.Label("Brush Width", GUILayout.MaxWidth(mw));
            _brushWidth = GUILayout.SelectionGrid(_brushWidth, brushWidths, brushWidths.Length, GUILayout.MaxWidth(mw), GUILayout.Height(h));
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            mw = 32 * brushShapes.Length;
            GUILayout.Label("Brush Shape", GUILayout.MaxWidth(mw));
            _brushShape = GUILayout.SelectionGrid(_brushShape, brushShapes, brushShapes.Length, GUILayout.MaxWidth(mw), GUILayout.Height(h));
            EditorGUILayout.EndVertical();

            GUI.contentColor = prevContentColor;

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


            EditorGUILayout.EndVertical(); // top buttons
        }
コード例 #17
0
ファイル: TGSInspector.cs プロジェクト: mengtest/CYMCommon
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label(_headerTexture, GUILayout.ExpandWidth(true));
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;


            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            DrawTitleLabel("Grid Configuration");
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Help"))
            {
                EditorUtility.DisplayDialog("Terrain Grid System", "TGS is an advanced grid generator for Unity terrain. It can also work as a standalone 2D grid.\n\nFor a complete description of the options, please refer to the documentation guide (PDF) included in the asset.\nWe also invite you to visit and sign up on our support forum on kronnect.com where you can post your questions/requests.\n\nThanks for purchasing! Please rate Terrain Grid System on the Asset Store! Thanks.", "Close");
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Topology", GUILayout.Width(120));
            tgs.gridTopology = (GRID_TOPOLOGY)EditorGUILayout.IntPopup((int)tgs.gridTopology, topologyOptions, topologyOptionsValues);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Territories", GUILayout.Width(120));
            tgs.numTerritories = EditorGUILayout.IntSlider(tgs.numTerritories, 1, Mathf.Min(tgs.numCells, TerrainGridSystem.MAX_TERRITORIES));
            EditorGUILayout.EndHorizontal();

            if (tgs.gridTopology == GRID_TOPOLOGY.Irregular)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Cells (aprox.)", GUILayout.Width(120));
                tgs.numCells = EditorGUILayout.IntField(tgs.numCells, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Columns", GUILayout.Width(120));
                tgs.columnCount = EditorGUILayout.IntField(tgs.columnCount, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Rows", GUILayout.Width(120));
                tgs.rowCount = EditorGUILayout.IntField(tgs.rowCount, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
            }
            if (tgs.gridTopology == GRID_TOPOLOGY.Hexagonal)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Regular Hexes", GUILayout.Width(120));
                tgs.regularHexagons = EditorGUILayout.Toggle(tgs.regularHexagons);
                EditorGUILayout.EndHorizontal();
                if (tgs.regularHexagons)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("   Hex Width", GUILayout.Width(120));
                    tgs.regularHexagonsWidth = EditorGUILayout.FloatField(tgs.regularHexagonsWidth);
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Even Layout", GUILayout.Width(120));
                tgs.evenLayout = EditorGUILayout.Toggle(tgs.evenLayout);
                EditorGUILayout.EndHorizontal();
            }

            if (tgs.gridTopology == GRID_TOPOLOGY.Irregular)
            {
                if (tgs.numCells > 10000)
                {
                    EditorGUILayout.HelpBox("Total cell count exceeds recommended maximum of 10.000!", MessageType.Warning);
                }
            }
            else if (tgs.numCells > 50000)
            {
                EditorGUILayout.HelpBox("Total cell count exceeds recommended maximum of 50.000!", MessageType.Warning);
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Curvature", GUILayout.Width(120));
            if (tgs.numCells > TerrainGridSystem.MAX_CELLS_FOR_CURVATURE)
            {
                DrawInfoLabel("not available with >" + TerrainGridSystem.MAX_CELLS_FOR_CURVATURE + " cells");
            }
            else
            {
                tgs.gridCurvature = EditorGUILayout.Slider(tgs.gridCurvature, 0, 0.1f);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Relaxation", GUILayout.Width(120));
            if (tgs.gridTopology != GRID_TOPOLOGY.Irregular)
            {
                DrawInfoLabel("only available with irregular topology");
            }
            else if (tgs.numCells > TerrainGridSystem.MAX_CELLS_FOR_RELAXATION)
            {
                DrawInfoLabel("not available with >" + TerrainGridSystem.MAX_CELLS_FOR_RELAXATION + " cells");
            }
            else
            {
                tgs.gridRelaxation = EditorGUILayout.IntSlider(tgs.gridRelaxation, 1, 32);
            }
            EditorGUILayout.EndHorizontal();

            if (tgs.terrain != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Roughness", GUILayout.Width(120));
                tgs.gridRoughness = EditorGUILayout.Slider(tgs.gridRoughness, 0f, 0.2f);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Seed", GUILayout.Width(120));
            tgs.seed = EditorGUILayout.IntSlider(tgs.seed, 1, 10000);
            if (GUILayout.Button("Redraw"))
            {
                tgs.Redraw();
            }
            if (GUILayout.Button("Clear"))
            {
                if (EditorUtility.DisplayDialog("Clear All", "Remove any color/texture from cells and territories?", "Ok", "Cancel"))
                {
                    tgs.ClearAll();
                }
            }
            EditorGUILayout.EndHorizontal();

            if (tgs.terrain != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Max Slope", GUILayout.Width(120));
                tgs.cellsMaxSlope = EditorGUILayout.Slider(tgs.cellsMaxSlope, 0, 1f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Minimum Altitude", GUILayout.Width(120));
                tgs.cellsMinimumAltitude = EditorGUILayout.FloatField(tgs.cellsMinimumAltitude, GUILayout.Width(120));
                if (tgs.cellsMinimumAltitude == 0)
                {
                    DrawInfoLabel("(0 = not used)");
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Mask", "Alpha channel is used to determine cell visibility (0 = cell is not visible)"), GUILayout.Width(120));
            tgs.gridMask = (Texture2D)EditorGUILayout.ObjectField(tgs.gridMask, typeof(Texture2D), true);
            EditorGUILayout.EndHorizontal();
            if (CheckTextureImportSettings(tgs.gridMask))
            {
                tgs.ReloadGridMask();
            }

            if (tgs.gridMask != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("   Use Scale", "Respects offset and scale parameters when applying mask."), GUILayout.Width(120));
                tgs.gridMaskUseScale = EditorGUILayout.Toggle(tgs.gridMaskUseScale);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Territories Texture", "Quickly create territories assigning a color texture in which each territory corresponds to a color."), GUILayout.Width(120));
            tgs.territoriesTexture = (Texture2D)EditorGUILayout.ObjectField(tgs.territoriesTexture, typeof(Texture2D), true);
            if (tgs.territoriesTexture != null)
            {
                EditorGUILayout.EndHorizontal();
                CheckTextureImportSettings(tgs.territoriesTexture);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("  Neutral Color", "Color to be ignored."), GUILayout.Width(120));
                                #if UNITY_2018_1_OR_NEWER
                tgs.territoriesTextureNeutralColor = EditorGUILayout.ColorField(new GUIContent(""), tgs.territoriesTextureNeutralColor, false, false, false, GUILayout.Width(50));
                                #else
                tgs.territoriesTextureNeutralColor = EditorGUILayout.ColorField(new GUIContent(""), tgs.territoriesTextureNeutralColor, false, false, false, null, GUILayout.Width(50));
                                #endif
                EditorGUILayout.Space();
                if (GUILayout.Button("Generate Territories", GUILayout.Width(120)))
                {
                    tgs.CreateTerritories(tgs.territoriesTexture, tgs.territoriesTextureNeutralColor);
                }
            }
            EditorGUILayout.EndHorizontal();

            int cellsCreated       = tgs.cells == null ? 0 : tgs.cells.Count;
            int territoriesCreated = tgs.territories == null ? 0 : tgs.territories.Count;

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            DrawInfoLabel("Cells Created: " + cellsCreated + " / Territories Created: " + territoriesCreated + " / Vertex Count: " + tgs.lastVertexCount);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            DrawTitleLabel("Grid Positioning");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Hide Objects", GUILayout.Width(120));
            if (tgs.terrain != null && GUILayout.Button("Toggle Terrain"))
            {
                tgs.terrain.enabled = !tgs.terrain.enabled;
            }
            if (GUILayout.Button("Toggle Grid"))
            {
                tgs.gameObject.SetActive(!tgs.gameObject.activeSelf);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Center", GUILayout.Width(120));
            tgs.gridCenter = EditorGUILayout.Vector2Field("", tgs.gridCenter);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Scale", GUILayout.Width(120));
            if (tgs.regularHexagons)
            {
                GUI.enabled = false;
            }
            tgs.gridScale = EditorGUILayout.Vector2Field("", tgs.gridScale);
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;

            if (tgs.gridTopology == GRID_TOPOLOGY.Hexagonal && tgs.regularHexagons)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(120));
                EditorGUILayout.HelpBox("Scale is driven by regular hexagons option.", MessageType.Info);
                EditorGUILayout.EndHorizontal();
            }
            else if (tgs.gridTopology != GRID_TOPOLOGY.Irregular)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Match Cell Size", GUILayout.Width(120));
                cellSize = EditorGUILayout.Vector2Field("", cellSize);
                if (GUILayout.Button("Set", GUILayout.Width(40)))
                {
                    tgs.cellSize = cellSize;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Mesh Depth Offset", GUILayout.Width(120));
            tgs.gridMeshDepthOffset = EditorGUILayout.IntSlider(tgs.gridMeshDepthOffset, -100, 0);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Colored Depth Offset", GUILayout.Width(120));
            tgs.gridSurfaceDepthOffset = EditorGUILayout.IntSlider(tgs.gridSurfaceDepthOffset, -200, 0);
            EditorGUILayout.EndHorizontal();

            if (tgs.terrain != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Elevation", GUILayout.Width(120));
                tgs.gridElevation = EditorGUILayout.Slider(tgs.gridElevation, 0f, 5f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Elevation Base", GUILayout.Width(120));
                tgs.gridElevationBase = EditorGUILayout.FloatField(tgs.gridElevationBase, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Camera Offset", GUILayout.Width(120));
                tgs.gridCameraOffset = EditorGUILayout.Slider(tgs.gridCameraOffset, 0, 0.1f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Normal Offset", GUILayout.Width(120));
                tgs.gridNormalOffset = EditorGUILayout.Slider(tgs.gridNormalOffset, 0.00f, 5f);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Camera", "The camera used for some calculations. Main camera is picked by default."), GUILayout.Width(120));
            tgs.cameraMain = (Camera)EditorGUILayout.ObjectField(tgs.cameraMain, typeof(Camera), true);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            DrawTitleLabel("Grid Appearance");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Show Territories", GUILayout.Width(120));
            tgs.showTerritories = EditorGUILayout.Toggle(tgs.showTerritories);
            GUILayout.Label("Frontier Color");
            tgs.territoryFrontiersColor = EditorGUILayout.ColorField(tgs.territoryFrontiersColor, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("  Highlight Color", GUILayout.Width(120));
            tgs.territoryHighlightColor = EditorGUILayout.ColorField(tgs.territoryHighlightColor, GUILayout.Width(50));
            GUILayout.FlexibleSpace();
            GUILayout.Label(new GUIContent("Disputed Frontier", "Color for common frontiers between two territories."));
            tgs.territoryDisputedFrontierColor = EditorGUILayout.ColorField(tgs.territoryDisputedFrontierColor, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("  Colorize Territories", GUILayout.Width(120));
            tgs.colorizeTerritories = EditorGUILayout.Toggle(tgs.colorizeTerritories);
            GUILayout.Label("Alpha");
            tgs.colorizedTerritoriesAlpha = EditorGUILayout.Slider(tgs.colorizedTerritoriesAlpha, 0.0f, 1.0f);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("  Outer Borders", GUILayout.Width(120));
            tgs.showTerritoriesOuterBorders = EditorGUILayout.Toggle(tgs.showTerritoriesOuterBorders);
            GUILayout.Label(new GUIContent("Internal Territories", "Allows territories to be contained by other territories."));
            tgs.allowTerritoriesInsideTerritories = EditorGUILayout.Toggle(tgs.allowTerritoriesInsideTerritories);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Show Cells", GUILayout.Width(120));
            tgs.showCells = EditorGUILayout.Toggle(tgs.showCells);
            if (tgs.showCells)
            {
                GUILayout.Label("Border Color", GUILayout.Width(120));
                tgs.cellBorderColor = EditorGUILayout.ColorField(tgs.cellBorderColor, GUILayout.Width(50));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("  Thickness", GUILayout.Width(120));
                tgs.cellBorderThickness = EditorGUILayout.Slider(tgs.cellBorderThickness, 1f, 5f);
                if (tgs.cellBorderThickness > 1f)
                {
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.HelpBox("Setting thickness value greater than 1 uses geometry shader (shader model 4.0 required, might not work on some mobile devices)", MessageType.Info);
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("  Highlight Color", GUILayout.Width(120));
            tgs.cellHighlightColor = EditorGUILayout.ColorField(tgs.cellHighlightColor, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Highlight Fade", GUILayout.Width(120));
            float highlightFadeMin    = tgs.highlightFadeMin;
            float highlightFadeAmount = tgs.highlightFadeAmount;
            EditorGUILayout.MinMaxSlider(ref highlightFadeMin, ref highlightFadeAmount, 0.0f, 1.0f);
            tgs.highlightFadeMin    = highlightFadeMin;
            tgs.highlightFadeAmount = highlightFadeAmount;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Highlight Speed", GUILayout.Width(120));
            tgs.highlightFadeSpeed = EditorGUILayout.Slider(tgs.highlightFadeSpeed, 0.1f, 5.0f);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Highlight Effect", GUILayout.Width(120));
            tgs.highlightEffect = (HIGHLIGHT_EFFECT)EditorGUILayout.EnumPopup(tgs.highlightEffect);
            EditorGUILayout.EndHorizontal();

            if (tgs.highlightEffect == HIGHLIGHT_EFFECT.TextureScale)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("   Scale Range", GUILayout.Width(120));
                float highlightScaleMin = tgs.highlightScaleMin;
                float highlightScaleMax = tgs.highlightScaleMax;
                EditorGUILayout.MinMaxSlider(ref highlightScaleMin, ref highlightScaleMax, 0.0f, 2.0f);
                if (GUILayout.Button("Default", GUILayout.Width(60)))
                {
                    highlightScaleMin = 0.75f;
                    highlightScaleMax = 1.1f;
                }
                tgs.highlightScaleMin = highlightScaleMin;
                tgs.highlightScaleMax = highlightScaleMax;
                EditorGUILayout.EndHorizontal();
            }

            if (tgs.terrain != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Near Clip Fade", "Fades out the cell and territories lines near to the camera."), GUILayout.Width(120));
                tgs.nearClipFadeEnabled = EditorGUILayout.Toggle(tgs.nearClipFadeEnabled);
                EditorGUILayout.EndHorizontal();

                if (tgs.nearClipFadeEnabled)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("  Distance", GUILayout.Width(120));
                    tgs.nearClipFade = EditorGUILayout.Slider(tgs.nearClipFade, 0.0f, 100.0f);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("  FallOff", GUILayout.Width(120));
                    tgs.nearClipFadeFallOff = EditorGUILayout.Slider(tgs.nearClipFadeFallOff, 0.001f, 100.0f);
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Canvas Texture", GUILayout.Width(120));
            tgs.canvasTexture = (Texture2D)EditorGUILayout.ObjectField(tgs.canvasTexture, typeof(Texture2D), true);
            EditorGUILayout.EndHorizontal();

            if (tgs.terrain == null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Transparent Background", GUILayout.Width(120));
                tgs.transparentBackground = EditorGUILayout.Toggle(tgs.transparentBackground);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            DrawTitleLabel("Grid Behaviour");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Terrain", GUILayout.Width(120));
            Terrain prevTerrain = tgs.terrain;
            tgs.terrain = (Terrain)EditorGUILayout.ObjectField(tgs.terrain, typeof(Terrain), true);
            if (tgs.terrain != prevTerrain)
            {
                GUIUtility.ExitGUI();
                return;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Selection Mode", GUILayout.Width(120));
            tgs.highlightMode = (HIGHLIGHT_MODE)EditorGUILayout.Popup((int)tgs.highlightMode, selectionModeOptions);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("  Include Invisible Cells", GUILayout.Width(120));
            tgs.cellHighlightNonVisible = EditorGUILayout.Toggle(tgs.cellHighlightNonVisible, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("  Minimum Distance", "Minimum distance of cell/territory to camera to be selectable. Useful in first person view to prevent selecting cells already under character."), GUILayout.Width(120));
            tgs.highlightMinimumTerrainDistance = EditorGUILayout.FloatField(tgs.highlightMinimumTerrainDistance, GUILayout.Width(60));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("  Highlight While Drag", "Allows highlight while dragging."), GUILayout.Width(120));
            tgs.allowHighlightWhileDragging = EditorGUILayout.Toggle(tgs.allowHighlightWhileDragging);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Overlay Mode", GUILayout.Width(120));
            tgs.overlayMode = (OVERLAY_MODE)EditorGUILayout.Popup((int)tgs.overlayMode, overlayModeOptions);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Respect Other UI", GUILayout.Width(120));
            tgs.respectOtherUI = EditorGUILayout.Toggle(tgs.respectOtherUI);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            DrawTitleLabel("Path Finding");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Algorithm", GUILayout.Width(120));
            tgs.pathFindingHeuristicFormula = (TGS.PathFinding.HeuristicFormula)EditorGUILayout.EnumPopup(tgs.pathFindingHeuristicFormula);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Max Search Cost", GUILayout.Width(120));
            tgs.pathFindingMaxCost = EditorGUILayout.FloatField(tgs.pathFindingMaxCost, GUILayout.Width(100));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Max Steps", GUILayout.Width(120));
            tgs.pathFindingMaxSteps = EditorGUILayout.IntField(tgs.pathFindingMaxSteps, GUILayout.Width(100));
            EditorGUILayout.EndHorizontal();

            if (tgs.gridTopology == GRID_TOPOLOGY.Box)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Use Diagonals", GUILayout.Width(120));
                tgs.pathFindingUseDiagonals = EditorGUILayout.Toggle(tgs.pathFindingUseDiagonals, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("   Diagonals Cost", GUILayout.Width(120));
                tgs.pathFindingHeavyDiagonalsCost = EditorGUILayout.FloatField(tgs.pathFindingHeavyDiagonalsCost, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
            }

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

            if (!Application.isPlaying)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal();
                DrawTitleLabel("Grid Editor");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Export Settings"))
                {
                    if (EditorUtility.DisplayDialog("Export Grid Settings", "This option will add a TGS Config component to this game object with current cell settings. You can restore this configuration just enabling this new component.", "Ok", "Cancel"))
                    {
                        CreatePlaceholder();
                    }
                }
                if (GUILayout.Button("Reset"))
                {
                    if (EditorUtility.DisplayDialog("Reset Grid", "Reset cells to their default values?", "Ok", "Cancel"))
                    {
                        ResetCells();
                        GUIUtility.ExitGUI();
                        return;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Enable Editor", "Enables grid editing options in Scene View"), GUILayout.Width(120));
                tgs.enableGridEditor = EditorGUILayout.Toggle(tgs.enableGridEditor);
                EditorGUILayout.EndHorizontal();

                if (tgs.enableGridEditor)
                {
                    int selectedCount = cellSelectedIndices.Count;
                    if (selectedCount == 0)
                    {
                        GUILayout.Label("Click on a cell in Scene View to edit its properties\n(use Control or Shift to select multiple cells)");
                    }
                    else
                    {
                        // Check that all selected cells are within range
                        for (int k = 0; k < selectedCount; k++)
                        {
                            if (cellSelectedIndices [k] < 0 || cellSelectedIndices [k] >= tgs.cellCount)
                            {
                                cellSelectedIndices.Clear();
                                EditorGUIUtility.ExitGUI();
                                return;
                            }
                        }

                        int cellSelectedIndex = cellSelectedIndices [0];
                        EditorGUILayout.BeginHorizontal();
                        if (selectedCount == 1)
                        {
                            GUILayout.Label("Selected Cell", GUILayout.Width(120));
                            GUILayout.Label(cellSelectedIndex.ToString(), GUILayout.Width(120));
                        }
                        else
                        {
                            GUILayout.Label("Selected Cells", GUILayout.Width(120));
                            sb.Length = 0;
                            for (int k = 0; k < selectedCount; k++)
                            {
                                if (k > 0)
                                {
                                    sb.Append(", ");
                                }
                                sb.Append(cellSelectedIndices [k].ToString());
                            }
                            if (selectedCount > 5)
                            {
                                GUILayout.TextArea(sb.ToString(), GUILayout.ExpandHeight(true));
                            }
                            else
                            {
                                GUILayout.Label(sb.ToString());
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        bool needsRedraw = false;

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("  Visible", GUILayout.Width(120));
                        Cell selectedCell = tgs.cells [cellSelectedIndex];
                        bool cellVisible  = selectedCell.visible;
                        selectedCell.visible = EditorGUILayout.Toggle(cellVisible);
                        if (selectedCell.visible != cellVisible)
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                tgs.cells [cellSelectedIndices [k]].visible = selectedCell.visible;
                            }
                            needsRedraw = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        if (selectedCount == 1)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("  Tag", GUILayout.Width(120));
                            cellTag = EditorGUILayout.IntField(cellTag, GUILayout.Width(60));
                            if (cellTag == selectedCell.tag)
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button("Set Tag", GUILayout.Width(60)))
                            {
                                tgs.CellSetTag(cellSelectedIndex, cellTag);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        GUI.enabled = true;
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("  Territory Index", GUILayout.Width(120));
                        cellTerritoryIndex = EditorGUILayout.IntField(cellTerritoryIndex, GUILayout.Width(40));
                        if (cellTerritoryIndex == selectedCell.territoryIndex)
                        {
                            GUI.enabled = false;
                        }
                        if (GUILayout.Button("Set Territory", GUILayout.Width(100)))
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                tgs.CellSetTerritory(cellSelectedIndices [k], cellTerritoryIndex);
                            }
                            needsRedraw = true;
                        }
                        GUI.enabled = true;
                        if (GUILayout.Button("Export Territory Mesh", GUILayout.Width(150)))
                        {
                            tgs.ExportTerritoryMesh(cellTerritoryIndex);
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("  Color", GUILayout.Width(120));
                        cellColor = EditorGUILayout.ColorField(cellColor, GUILayout.Width(40));
                        GUILayout.Label("  Texture", GUILayout.Width(60));
                        cellTextureIndex = EditorGUILayout.IntField(cellTextureIndex, GUILayout.Width(40));
                        if (tgs.CellGetColor(cellSelectedIndex) == cellColor && tgs.CellGetTextureIndex(cellSelectedIndex) == cellTextureIndex)
                        {
                            GUI.enabled = false;
                        }
                        if (GUILayout.Button("Set", GUILayout.Width(40)))
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                tgs.CellToggleRegionSurface(cellSelectedIndices [k], true, cellColor, false, cellTextureIndex);
                            }
                            needsRedraw = true;
                        }
                        GUI.enabled = true;
                        if (GUILayout.Button("Clear", GUILayout.Width(40)))
                        {
                            for (int k = 0; k < selectedCount; k++)
                            {
                                tgs.CellHideRegionSurface(cellSelectedIndices [k]);
                            }
                            needsRedraw = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        if (needsRedraw)
                        {
                            RefreshGrid();
                            GUIUtility.ExitGUI();
                            return;
                        }
                    }

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Textures", GUILayout.Width(120));
                    EditorGUILayout.EndHorizontal();

                    if (toggleButtonStyleNormal == null)
                    {
                        toggleButtonStyleNormal  = "Button";
                        toggleButtonStyleToggled = new GUIStyle(toggleButtonStyleNormal);
                        toggleButtonStyleToggled.normal.background = toggleButtonStyleToggled.active.background;
                    }

                    int textureMax = tgs.textures.Length - 1;
                    while (textureMax >= 1 && tgs.textures [textureMax] == null)
                    {
                        textureMax--;
                    }
                    textureMax++;
                    if (textureMax >= tgs.textures.Length)
                    {
                        textureMax = tgs.textures.Length - 1;
                    }

                    for (int k = 1; k <= textureMax; k++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("  " + k.ToString(), GUILayout.Width(40));
                        tgs.textures [k] = (Texture2D)EditorGUILayout.ObjectField(tgs.textures [k], typeof(Texture2D), false);
                        if (tgs.textures [k] != null)
                        {
                            if (GUILayout.Button(new GUIContent("T", "Texture mode - if enabled, you can paint several cells just clicking over them."), textureMode == k ? toggleButtonStyleToggled : toggleButtonStyleNormal, GUILayout.Width(20)))
                            {
                                textureMode = textureMode == k ? 0 : k;
                            }
                            if (GUILayout.Button(new GUIContent("X", "Remove texture"), GUILayout.Width(20)))
                            {
                                if (EditorUtility.DisplayDialog("Remove texture", "Are you sure you want to remove this texture?", "Yes", "No"))
                                {
                                    tgs.textures [k] = null;
                                    GUIUtility.ExitGUI();
                                    return;
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.Separator();

            if (tgs.isDirty)
            {
                                #if UNITY_5_6_OR_NEWER
                serializedObject.UpdateIfRequiredOrScript();
                                #else
                serializedObject.UpdateIfDirtyOrScript();
                                #endif
                if (isDirty == null)
                {
                    OnEnable();
                }
                isDirty.boolValue = false;
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);

                // Hide mesh in Editor
                HideEditorMesh();

                SceneView.RepaintAll();
            }
        }
コード例 #18
0
        public void Render(Rect rect)
        {
            if (Event.current.type == EventType.Repaint)
            {
                bool abortGUI = false;

                if (_eventInspector != null && _eventInspector.target == null)
                {
                    abortGUI = true;
                    SetEvents(null);
                }

                if (_trackInspector != null && _trackInspector.target == null)
                {
                    abortGUI = true;
                    SetTracks(null);
                }

                if (abortGUI)
                {
                    EditorGUIUtility.ExitGUI();
                    return;
                }
            }

            float contentWidth = rect.width;

            if (rect.height < _viewRect.height)
            {
                contentWidth -= 20;
                //				_viewRect.xMax -= 20;
            }

            _scroll = GUI.BeginScrollView(rect, _scroll, _viewRect);

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);

            if (_eventInspector != null)
            {
                EditorGUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Width(contentWidth));
                EditorGUILayout.LabelField("Events:", EditorStyles.boldLabel);
                if (_eventInspector.target != null)
                {
                    _eventInspector.OnInspectorGUI();
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (_trackInspector != null)
            {
                EditorGUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Width(contentWidth));
                EditorGUILayout.LabelField("Tracks:", EditorStyles.boldLabel);
                if (_trackInspector.target != null)
                {
                    _trackInspector.OnInspectorGUI();
                }
                EditorGUILayout.EndVertical();
            }

            if (Event.current.type == EventType.Repaint && (_eventInspector != null || _trackInspector != null))
            {
                Rect lastElementRect = GUILayoutUtility.GetLastRect();

                _viewRect = rect;

                _viewRect.height = Mathf.Max(_viewRect.height, lastElementRect.y + lastElementRect.height);
            }

            GUI.EndScrollView();
        }
コード例 #19
0
    static void    DrawDllRegion(ref int selectedDllIndex, string[] assemblyNames)
    {
        //	dllName = EditorGUILayout.TextField (dllName, s_expandWidthOption);

        //	prefabWithDllScripts = (GameObject) EditorGUILayout.ObjectField ("prefab with dll scripts", prefabWithDllScripts, typeof(GameObject),
        //		false, s_expandWidthOption);

        selectedDllIndex = GUILayout.SelectionGrid(selectedDllIndex, assemblyNames, 4);

        GUILayout.Space(5);

        if (GUILayout.Button("List all scripts from dll", s_expandWidthOption))
        {
            int count = 0;
            foreach (var scriptId in MetaFileUtils.ListDllScripts(assemblyNames[selectedDllIndex]))
            {
                Debug.Log(scriptId.type + ", guid: " + scriptId.guid + ", fileId: " + scriptId.fileId);
                count++;
            }
            Debug.Log("Total of " + count + " scripts");
        }

        if (GUILayout.Button("Save script ids to xml file", s_expandWidthOption))
        {
            var scriptIds = MetaFileUtils.ListDllScripts(assemblyNames [selectedDllIndex]).ToArray();

            string filePath = EditorUtility.SaveFilePanel("Save script ids to file", "", "scriptIds.xml", "xml");

            if (!string.IsNullOrEmpty(filePath))
            {
                MetaFileUtils.SaveScriptIdsToXmlFile(scriptIds, filePath);
                Debug.LogFormat("Saved {0} script ids to file", scriptIds.Length);
            }

            EditorGUIUtility.ExitGUI();
        }

        /*
         * if (GUILayout.Button ("List all scripts using prefab", s_expandWidthOption)) {
         *
         *      var scriptIds = MetaFileUtils.FindPrefabScriptIds (prefabWithDllScripts);
         *      foreach (var id in scriptIds) {
         *              Debug.Log ("fileId " + id.fileId + ", guid " + id.guid);
         *      }
         *      Debug.Log ("Total " + scriptIds.Count + " scripts");
         *
         * }
         *
         * if (GUILayout.Button ("Compare script ids", s_expandWidthOption)) {
         *
         *      var scriptIdsFromPrefab = MetaFileUtils.FindPrefabScriptIds (prefabWithDllScripts);
         *      var scriptIdsFromDll = MetaFileUtils.ListDllScripts (dllName).ToList();
         *
         *      int countNotFound = 0;
         *
         *      foreach (var id in scriptIdsFromPrefab) {
         *              if(!scriptIdsFromDll.Exists( id_ => id_.fileId == id.fileId && id_.guid == id.guid)) {
         *                      Debug.LogWarning("script with fileId " + id.fileId + " not found in dll scripts" );
         *                      countNotFound++;
         *              }
         *      }
         *
         *      Debug.Log ("Comparison finished - num scripts from prefab " + scriptIdsFromPrefab.Count +
         *              ", num scripts from dll " + scriptIdsFromDll.Count + ", num not matching " + countNotFound);
         * }
         */
    }
コード例 #20
0
        public override void OnInspectorGUI()
        {
            ConstraintStack cstack = (ConstraintStack)target;

            serializedObject.Update();

            GUILayout.Space(3f);

            // constraints
            for (int i = 0; i < cstack.constraintCount; ++i)
            {
                BaseConstraint c = cstack.Get(i);
                if (!c)
                { //remove broken reference
                    cstack.RemoveAt(i);
                    --i;
                    continue;
                }

                // draw constraint & buttons
                EditorGUILayout.BeginHorizontal();
                {
                    Color btnColor = c.IsActiveConstraint ? Color.white : Color.red;
                    EUtil.PushBackgroundColor(btnColor);
                    var  content = new GUIContent(c.GetType().Name, "Click to fold other components");
                    Rect rc      = GUILayoutUtility.GetRect(content, EditorStyles.toolbarButton);
                    if (GUI.Button(rc, content, EditorStyles.toolbarButton))
                    {
                        _FoldComponents(cstack);
                        var wnd = EditorEditorWindow.OpenWindowWithActivatorRect(c, rc);
                        EUtil.SetEditorWindowTitle(wnd, content.text);
                    }
                    EditorGUI.ProgressBar(rc, c.Influence, content.text);
                    EUtil.PopBackgroundColor();

                    if (GUILayout.Button(new GUIContent(c.IsActiveConstraint ? EConUtil.activeBtn : EConUtil.inactiveBtn, "Toggle constraint active state"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        c.IsActiveConstraint = !c.IsActiveConstraint;
                        EditorUtility.SetDirty(cstack);
                    }

                    EUtil.PushGUIEnable(i != 0);
                    if (GUILayout.Button(new GUIContent(EConUtil.upBtn, "move up"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i - 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentUp(c);
                    }
                    EUtil.PopGUIEnable();

                    EUtil.PushGUIEnable(i != cstack.constraintCount - 1);
                    if (GUILayout.Button(new GUIContent(EConUtil.downBtn, "move down"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i + 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentDown(c);
                    }
                    EUtil.PopGUIEnable();

                    if (GUILayout.Button(new GUIContent(EConUtil.deleteBtn, "delete the constraint from stack"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        MUndo.RecordObject(cstack, "Remove Constraint");
                        cstack.RemoveAt(i);
                        EditorUtility.SetDirty(cstack);
                        _FoldComponents(cstack);
                        EditorGUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
            } //for(int i=0; i<cstack.constraintCount; ++i)

            GUILayout.Space(2f);

            EditorGUI.BeginChangeCheck();
            int newOrder = EditorGUILayout.IntField(new GUIContent("Exec Order", "used to help decide evaluation order, the smaller the earlier"), cstack.ExecOrder);

            if (EditorGUI.EndChangeCheck())
            {
                cstack.ExecOrder = newOrder;
            }

            { //new constraint window
                EUtil.DrawSplitter(new Color(1, 1, 1, 0.3f));

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15f);
                var  content = new GUIContent("Add Constraint", "Add new constraint into current stack");
                Rect btnRc   = GUILayoutUtility.GetRect(content, GUI.skin.button);
                if (GUI.Button(btnRc, content))
                {
                    var  wnd   = ScriptableObject.CreateInstance <ConstraintsWindow>();
                    Rect wndRc = EUtil.GetRectByActivatorRect(wnd.position, btnRc);
                    wnd.position = wndRc;
                    wnd.SetConstraintStack(cstack);
                    wnd.ShowPopup();
                    wnd.Focus();
                }
                GUILayout.Space(15f);
                EditorGUILayout.EndHorizontal();
            }


            if (Pref.ShowInitInfos)
            {
                EditorGUILayout.PropertyField(m_spInitInfo, true);
            }



            serializedObject.ApplyModifiedProperties();
        }
コード例 #21
0
 public void Cancel()
 {
     Reset();
     Undo.RevertAllInCurrentGroup();
     EditorGUIUtility.ExitGUI();
 }
コード例 #22
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        if (property.objectReferenceValue != null)
        {
            if (IsThereAnyVisibileProperty(property) && CheckAttribute(property.objectReferenceValue.GetType()))
            {
                property.isExpanded = EditorGUI.Foldout(new Rect(position.x, position.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), property.isExpanded, property.displayName, true);
            }
            else
            {
                EditorGUI.LabelField(new Rect(position.x, position.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), property.displayName);
                property.isExpanded = false;
            }

            EditorGUI.PropertyField(new Rect(EditorGUIUtility.labelWidth + 14, position.y, position.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), property, GUIContent.none, true);
            if (GUI.changed)
            {
                property.serializedObject.ApplyModifiedProperties();
            }
            if (property.objectReferenceValue == null)
            {
                EditorGUIUtility.ExitGUI();
            }

            if (property.isExpanded)
            {
                // Draw a background that shows us clearly which fields are part of the ScriptableObject
                GUI.Box(new Rect(0, position.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing - 1, Screen.width, position.height - EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing), "");

                EditorGUI.indentLevel++;
                var data = (ScriptableObject)property.objectReferenceValue;
                SerializedObject serializedObject = new SerializedObject(data);


                // Iterate over all the values and draw them
                SerializedProperty prop = serializedObject.GetIterator();
                float y = position.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                if (prop.NextVisible(true))
                {
                    do
                    {
                        // Don't bother drawing the class file
                        if (prop.name == "m_Script")
                        {
                            continue;
                        }
                        float height = EditorGUI.GetPropertyHeight(prop, new GUIContent(prop.displayName), true);
                        EditorGUI.PropertyField(new Rect(position.x, y, position.width, height), prop, true);
                        y += height + EditorGUIUtility.standardVerticalSpacing;
                    }while (prop.NextVisible(false));
                }
                if (GUI.changed)
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel--;
            }
        }
        else
        {
            EditorGUI.ObjectField(new Rect(position.x, position.y, position.width - 60, EditorGUIUtility.singleLineHeight), property);
            if (GUI.Button(new Rect(position.x + position.width - 58, position.y, 58, EditorGUIUtility.singleLineHeight), "Create"))
            {
                string selectedAssetPath = "Assets";
                if (property.serializedObject.targetObject is MonoBehaviour)
                {
                    MonoScript ms = MonoScript.FromMonoBehaviour((MonoBehaviour)property.serializedObject.targetObject);
                    selectedAssetPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(ms));
                }
                Type type = fieldInfo.FieldType;
                if (type.IsArray)
                {
                    type = type.GetElementType();
                }
                else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    type = type.GetGenericArguments()[0];
                }
                property.objectReferenceValue = CreateAssetWithSavePrompt(type, selectedAssetPath);
            }
        }
        property.serializedObject.ApplyModifiedProperties();
        EditorGUI.EndProperty();
    }
コード例 #23
0
        //-----------------------------------------------------------------------------------
        public override void RenderGUI(Rect area)
        {
            if (ownerNode_ == null)
            {
                CNFieldWindowBig.CloseIfOpen();
                EditorGUIUtility.ExitGUI();
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            DrawToolStrip();

            EditorGUILayout.EndHorizontal();

            Event ev = Event.current;

            EditorGUI.LabelField(new Rect(5f, 30f, area.width, 20f), "Selected Objects:");

            Rect listAreaObjects = new Rect(5f, 50f, Mathf.Ceil((area.width - 10f) / 2f - 30f), Mathf.Ceil(area.height - botMargin));
            Rect buttonRect      = new Rect(listAreaObjects.xMax + 10f, (listAreaObjects.yMax - listAreaObjects.yMin - buttonsHeight) / 2f + 30f, 40f, 35f);

            Rect listAreaNodes = new Rect(buttonRect.xMax + 10f, listAreaObjects.yMin, (area.width - 10f) / 2f - 30f, area.height - botMargin - buttonsHeight - 10f);
            Rect buttonsArea   = new Rect(buttonRect.xMax + 10f, listAreaNodes.yMax + 2f, listAreaNodes.width, buttonsHeight);

            Rect label1Area = new Rect(buttonRect.xMin + 10f, buttonsArea.yMin + 27f, 20f, 17f);
            Rect label2Area = new Rect(buttonRect.xMin + 10f, label1Area.yMax + 13f, 20f, 17f);

            EditorGUI.BeginDisabledGroup(!Controller.AreGameObjectsAllowed());

            EditorGUI.LabelField(label1Area, "<<");
            EditorGUI.LabelField(label2Area, "<<");

            EditorGUI.EndDisabledGroup();

            ProcessEvents(ev, listAreaObjects, listAreaNodes);

            EditorGUI.BeginDisabledGroup(!nodesController_.AnyNodeSelected);
            if (GUI.Button(buttonRect, "<<"))
            {
                nodesController_.AddSelectedNodes();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.LabelField(new Rect(buttonRect.xMax + 10f, 30f, area.width, 20f), "Selectable Nodes:");

            selectionListBox_.RenderGUI(listAreaObjects);
            nodesListBox_.RenderGUI(listAreaNodes);

            GUILayout.BeginArea(buttonsArea);

            EditorGUI.BeginChangeCheck();

            bool isShowOwnerGroupOnly = field_.ShowOwnerGroupOnly;

            GUIStyle styleToggle = new GUIStyle(EditorStyles.label);

            if (isShowOwnerGroupOnly)
            {
                styleToggle.fontStyle = FontStyle.Bold;
            }

            field_.ShowOwnerGroupOnly = EditorGUILayout.ToggleLeft("Show only owner group", isShowOwnerGroupOnly, styleToggle);
            if (EditorGUI.EndChangeCheck())
            {
                nodesController_.SetSelectableNodes();
                EditorUtility.SetDirty(ownerNode_);
            }

            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(!Controller.AreGameObjectsAllowed());
            if (GUILayout.Button("Name Selector"))
            {
                Controller.AddNameSelectorWindow();
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Game Object Selection"))
            {
                Controller.AddCurrentSelection();
            }
            EditorGUI.EndDisabledGroup();

            GUILayout.EndArea();
        }
コード例 #24
0
        public void OnGUI()
        {
            FSequence sequence = _sequenceWindow.GetSequenceEditor().GetSequence();

            if (_selectedSequenceIndex < 0 && sequence != null)
            {
                for (int i = 0; i != _sequences.Length; ++i)
                {
                    if (_sequences[i] == sequence)
                    {
                        _selectedSequenceIndex = i;
                        break;
                    }
                }
            }


            GUI.contentColor = FGUI.GetTextColor();

            if (Event.current.type == EventType.MouseDown && Event.current.alt && _sequencePopupRect.Contains(Event.current.mousePosition))
            {
                Selection.activeObject = sequence;
                Event.current.Use();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.PrefixLabel(_sequenceLabelRect, _sequenceLabel);
            int newSequenceIndex = EditorGUI.Popup(_sequencePopupRect, _selectedSequenceIndex, _sequenceNames);

            if (EditorGUI.EndChangeCheck())
            {
                _selectedSequenceIndex = newSequenceIndex;
                _sequenceWindow.GetSequenceEditor().OpenSequence(_sequences[_selectedSequenceIndex]);
                _sequenceWindow.RemoveNotification();
                EditorGUIUtility.keyboardControl = 0;                 // deselect it
                EditorGUIUtility.ExitGUI();
            }

            if (GUI.Button(_sequenceAddButtonRect, new GUIContent((Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)), "Create New Sequence.."), EditorStyles.label))
            {
                FSequence newSequence = FSequenceEditorWindow.CreateSequence();
                _sequenceWindow.GetSequenceEditor().OpenSequence(newSequence);
                EditorGUIUtility.ExitGUI();
            }

            if (sequence == null)
            {
                return;
            }

            if (_sequenceSO == null || _sequenceSO.targetObject != sequence)
            {
                _sequenceSO         = new SerializedObject(sequence);
                _sequenceUpdateMode = _sequenceSO.FindProperty("_updateMode");
                _sequenceLength     = _sequenceSO.FindProperty("_length");
            }

            _sequenceSO.Update();

            if (_showUpdadeMode)
            {
                EditorGUI.PrefixLabel(_updateModeLabelRect, _updateModeLabel);
                EditorGUI.PropertyField(_updateModeFieldRect, _sequenceUpdateMode, GUIContent.none);
            }

            if (_showFramerate)
            {
                EditorGUI.PrefixLabel(_framerateLabelRect, _framerateLabel);
                EditorGUI.BeginChangeCheck();
                int newFrameRate = FGUI.FrameRatePopup(_framerateFieldRect, sequence.FrameRate);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newFrameRate == -1)
                    {
                        FChangeFrameRateWindow.Show(new Vector2(_framerateLabelRect.xMin, _framerateLabelRect.yMax), sequence, FSequenceInspector.Rescale);
                    }
                    else
                    {
                        FSequenceInspector.Rescale(sequence, newFrameRate, true);
                    }
                }
            }

            if (_showLength)
            {
                EditorGUI.PrefixLabel(_lengthLabelRect, _lengthLabel);
                _sequenceLength.intValue = EditorGUI.IntField(_lengthFieldRect, _sequenceLength.intValue, _numberFieldStyle);
            }

            _sequenceSO.ApplyModifiedProperties();
        }
コード例 #25
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Show script link
            _script = EditorGUILayout.ObjectField("Script", _script, typeof(MonoScript), false) as MonoScript;

            // ProCamera2D
            _tooltip = new GUIContent("Pro Camera 2D", "");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ProCamera2D"), _tooltip);

            if (_proCamera2DParallax.ProCamera2D == null)
            {
                EditorGUILayout.HelpBox("ProCamera2D is not set.", MessageType.Error, true);
            }

            _proCamera2D = _proCamera2DParallax.ProCamera2D;
            if (_proCamera2D == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            // Parallax layers List
            _parallaxLayersList.DoLayoutList();

            var areSpeedsNotOrdered    = false;
            var isLayerMaskEmpty       = false;
            var isLayerMaskOverlapping = false;

            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                // Detect unordered speeds
                if (i < _proCamera2DParallax.ParallaxLayers.Count - 1)
                {
                    if (_proCamera2DParallax.ParallaxLayers[i].Speed > _proCamera2DParallax.ParallaxLayers[i + 1].Speed)
                    {
                        areSpeedsNotOrdered = true;
                    }
                }

                // Detect empty layer masks
                if (_proCamera2DParallax.ParallaxLayers[i].LayerMask.value == 0)
                {
                    isLayerMaskEmpty = true;
                }

                // Detect equal layer masks
                for (int j = 0; j < _proCamera2DParallax.ParallaxLayers.Count; j++)
                {
                    if (i != j && _proCamera2DParallax.ParallaxLayers[i].LayerMask.value == _proCamera2DParallax.ParallaxLayers[j].LayerMask.value)
                    {
                        isLayerMaskOverlapping = true;
                    }
                }

                // Remove layers with no camera assigned
                if (_proCamera2DParallax.ParallaxLayers[i].ParallaxCamera == null)
                {
                    _proCamera2DParallax.ParallaxLayers.RemoveAt(i);
                    EditorGUIUtility.ExitGUI();
                    continue;
                }

                // Apply layer masks as camera culling mask
                _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.cullingMask = _proCamera2DParallax.ParallaxLayers[i].LayerMask;

                // Setup clear flags
                if (_proCamera2DParallax.ParallaxLayers[0].Speed > 1)
                {
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                }
                else
                {
                    _proCamera2DParallax.ParallaxLayers[0].ParallaxCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.Depth;

                    if (i > 0)
                    {
                        _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                    }
                }
            }

            // Show warnings
            if (areSpeedsNotOrdered)
            {
                EditorGUILayout.HelpBox("Parallax layer speeds are not ordered.", MessageType.Warning, true);
            }

            if (isLayerMaskEmpty)
            {
                EditorGUILayout.HelpBox("One or more layer mask is empty.", MessageType.Warning, true);
            }

            if (isLayerMaskOverlapping)
            {
                EditorGUILayout.HelpBox("Two or more cameras are rendering the same layers. Check your Layer Masks.", MessageType.Warning, true);
            }


            // Setup depths
            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                if (_proCamera2DParallax.ParallaxLayers[i].Speed > 1)
                {
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth + (i + 1);
                }
                else
                {
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth - _proCamera2DParallax.ParallaxLayers.Count + (i);
                }
            }

            // Show correct axis name
            var hAxis = "";
            var vAxis = "";

            switch (_proCamera2D.Axis)
            {
            case MovementAxis.XY:
                hAxis = "X";
                vAxis = "Y";
                break;

            case MovementAxis.XZ:
                hAxis = "X";
                vAxis = "Z";
                break;

            case MovementAxis.YZ:
                hAxis = "Y";
                vAxis = "Z";
                break;
            }

            // Follow X
            _tooltip = new GUIContent("Parallax " + hAxis, "Should the parallax occur on the horizontal axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxHorizontal"), _tooltip);

            // Follow Y
            _tooltip = new GUIContent("Parallax " + vAxis, "Should the parallax occur on the vertical axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxVertical"), _tooltip);

            // Root Position
            _tooltip = new GUIContent("Root Position", "The position at which your camera is going to start.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RootPosition"), _tooltip);

            // Reset offset button
            if (GUILayout.Button("Set Root Position"))
            {
                switch (_proCamera2D.Axis)
                {
                case MovementAxis.XY:
                    _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, _proCamera2D.transform.localPosition.y, 0);
                    break;

                case MovementAxis.XZ:
                    _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, 0, _proCamera2D.transform.localPosition.z);
                    break;

                case MovementAxis.YZ:
                    _proCamera2DParallax.RootPosition = new Vector3(0, _proCamera2D.transform.localPosition.y, _proCamera2D.transform.localPosition.z);
                    break;
                }
            }


            serializedObject.ApplyModifiedProperties();
        }
コード例 #26
0
    public override void OnInspectorGUI()
    {
        Object[] targetObjects = serializedObject.targetObjects;

        EditorGUILayout.PropertyField(targetProjectFolder, new GUIContent("Project Folder"));
        EditorGUILayout.PropertyField(targetClipNames, new GUIContent("Clip Names"), true);

        EditorGUILayout.PropertyField(targetSheetResolution, new GUIContent("Sheet Resolution"));
        EditorGUILayout.PropertyField(targetColor, new GUIContent("Color"));
        EditorGUILayout.PropertyField(targetDepth, new GUIContent("Depth"));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Discretization Step");
        targetDiscretizationStep.intValue = (int)EditorGUILayout.Slider(targetDiscretizationStep.intValue, 1, 30);
        EditorGUILayout.EndHorizontal();

        foldRenderTarget = EditorGUILayout.Foldout(foldRenderTarget, "Render Target");
        if (foldRenderTarget)
        {
            ++EditorGUI.indentLevel;

            int  valueIndex1  = targetRenderTarget.enumValueIndex;
            bool isSameValue1 = !targetRenderTarget.hasMultipleDifferentValues;

            EditorGUILayout.PropertyField(targetRenderTarget, new GUIContent("Target"));

            int  valueIndex2  = targetRenderTarget.enumValueIndex;
            bool isSameValue2 = !targetRenderTarget.hasMultipleDifferentValues;

            if ((valueIndex1 != valueIndex2) ||
                !isSameValue1 && isSameValue2)
            {
                if (valueIndex2 == (int)HarmonyRenderer.RenderTarget.eScreen)
                {
                    foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                    {
                        GameObject rendererObject = harmonyRenderer.gameObject;
                        GenerateHarmonyMesh.ClearTextureObjectMesh(rendererObject);
                    }

                    //  Components were removed from ui.  Bail out now.
                    serializedObject.ApplyModifiedProperties();
                    EditorGUIUtility.ExitGUI();
                }
                else if (valueIndex2 == (int)HarmonyRenderer.RenderTarget.eRenderTexture)
                {
                    foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                    {
                        GameObject rendererObject = harmonyRenderer.gameObject;
                        GenerateHarmonyMesh.CreateOrUpdateTextureObjectMesh(rendererObject, true);
                    }

                    //  Components were removed from ui.  Bail out now.
                    serializedObject.ApplyModifiedProperties();
                    EditorGUIUtility.ExitGUI();
                }
            }

            GUI.enabled = (targetRenderTarget.enumValueIndex == (int)HarmonyRenderer.RenderTarget.eRenderTexture);
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Texture Resolution");

                bool disabled = true;
                if (targetObjects.Length == 1)
                {
                    HarmonyRenderer harmonyRenderer = targetObjects[0] as HarmonyRenderer;
                    GameObject      rendererObject  = harmonyRenderer.gameObject;

                    MeshFilter meshFilter = harmonyRenderer.gameObject.GetComponent <MeshFilter>();
                    if ((meshFilter != null) && (meshFilter.sharedMesh != null))
                    {
                        Bounds bounds         = meshFilter.sharedMesh.bounds;
                        float  meshResolution = Mathf.Max(bounds.size.x, bounds.size.y);
                        if (meshResolution > 0.0f)
                        {
                            float currentTextureScale = targetRenderTextureScale.floatValue;
                            float currentResolution   = meshResolution * currentTextureScale;
                            float newResolution       = EditorGUILayout.Slider(currentResolution, 32, 8192);

                            if (newResolution != currentResolution)
                            {
                                float newTextureScale = newResolution / meshResolution;
                                harmonyRenderer.renderTextureScale = newTextureScale;

                                GenerateHarmonyMesh.CreateOrUpdateTextureObjectMesh(rendererObject);

                                serializedObject.Update();
                            }

                            disabled = false;
                        }
                    }
                }

                if (disabled)
                {
                    bool wasEnabled = GUI.enabled;
                    GUI.enabled = false;
                    EditorGUILayout.Slider(32, 32, 8192);
                    GUI.enabled = wasEnabled;
                }

                EditorGUILayout.EndHorizontal();

                //EditorGUILayout.PropertyField(targetRenderTextureViewport, new GUIContent("Texture Viewport"));
                //EditorGUILayout.PropertyField(targetRenderTextureScale, new GUIContent("Texture Scale"));

                if (!Application.isPlaying)
                {
                    //  Regenerate Mesh
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(EditorGUI.indentLevel * TAB_SIZE);

                    if (GUILayout.Button("Generate Mesh", GUILayout.Width(120)))
                    {
                        foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                        {
                            GameObject rendererObject = harmonyRenderer.gameObject;
                            GenerateHarmonyMesh.CreateOrUpdateTextureObjectMesh(rendererObject, true);
                        }
                    }

                    if (GUILayout.Button("Clear Mesh", GUILayout.Width(120)))
                    {
                        foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                        {
                            GameObject rendererObject = harmonyRenderer.gameObject;
                            GenerateHarmonyMesh.ClearTextureObjectMesh(rendererObject);
                        }

                        //  Components were removed from ui.  Bail out now.
                        EditorGUIUtility.ExitGUI();
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            GUI.enabled = true;

            --EditorGUI.indentLevel;
        }

        foldColliders = EditorGUILayout.Foldout(foldColliders, "Colliders");
        if (foldColliders)
        {
            ++EditorGUI.indentLevel;

            EditorGUILayout.PropertyField(targetSyncCollider, new GUIContent("Sync Collider"));
            EditorGUILayout.PropertyField(targetColliderShape, new GUIContent("Collider Shape"));
            EditorGUILayout.PropertyField(targetColliderTrigger, new GUIContent("Collider Trigger"));

            if (!Application.isPlaying)
            {
                //  Update colliders
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * TAB_SIZE);

                if (GUILayout.Button("Generate Colliders", GUILayout.Width(120)))
                {
                    foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                    {
                        harmonyRenderer.PreCalculateColliders();
                    }

                    //  Components were removed from ui.  Bail out now.
                    EditorGUIUtility.ExitGUI();
                }

                if (GUILayout.Button("Clear Colliders", GUILayout.Width(120)))
                {
                    foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                    {
                        harmonyRenderer.ClearColliders();
                    }

                    //  Components were removed from ui.  Bail out now.
                    EditorGUIUtility.ExitGUI();
                }

                EditorGUILayout.EndHorizontal();
            }

            --EditorGUI.indentLevel;
        }

        foldMetadata = EditorGUILayout.Foldout(foldMetadata, "Metadata");
        if (foldMetadata)
        {
            ++EditorGUI.indentLevel;

            //  Override label width to 1 pixel...
            EditorGUIUtility.labelWidth = 1f;

            for (int i = 0; i < System.Math.Min(targetMetadataKeys.arraySize, targetMetadataLists.arraySize); ++i)
            {
                SerializedProperty targetMetadataKey       = targetMetadataKeys.GetArrayElementAtIndex(i);
                SerializedProperty targetMetadataContainer = targetMetadataLists.GetArrayElementAtIndex(i);

                SerializedProperty targetMetadataList = targetMetadataContainer.FindPropertyRelative("metas");

                EditorGUILayout.LabelField(targetMetadataKey.stringValue);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * TAB_SIZE);
                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal("box");

                GUILayout.Label("name ");
                GUILayout.Label("node");
                GUILayout.Label("value");

                if (GUILayout.Button("+", GUILayout.Width(16), GUILayout.Height(16)))
                {
                    ++targetMetadataList.arraySize;
                }

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

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * TAB_SIZE);
                EditorGUILayout.BeginVertical();
                for (int j = 0; j < targetMetadataList.arraySize; ++j)
                {
                    SerializedProperty targetMetadata = targetMetadataList.GetArrayElementAtIndex(j);

                    EditorGUILayout.BeginHorizontal("box");

                    SerializedProperty targetMetadataName     = targetMetadata.FindPropertyRelative("metaName");
                    SerializedProperty targetMetadataNodeName = targetMetadata.FindPropertyRelative("nodeName");
                    SerializedProperty targetMetadataValue    = targetMetadata.FindPropertyRelative("metaValue");

                    EditorGUILayout.PropertyField(targetMetadataName, new GUIContent(" "));
                    EditorGUILayout.PropertyField(targetMetadataNodeName, new GUIContent(" "));
                    EditorGUILayout.PropertyField(targetMetadataValue, new GUIContent(" "));

                    if (GUILayout.Button("-", GUILayout.Width(16), GUILayout.Height(16)))
                    {
                        targetMetadataList.DeleteArrayElementAtIndex(j);
                    }

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

            if (!Application.isPlaying)
            {
                //  Update props and anchors
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * TAB_SIZE);

                if (GUILayout.Button("Update All Metadata", GUILayout.Width(120)))
                {
                    foreach (HarmonyRenderer harmonyRenderer in targetObjects)
                    {
                        GameObject rendererObject = harmonyRenderer.gameObject;

                        //  Create Metadata.
                        GenerateHarmonyMeta.CreateOrUpdatePropsFromMetadata(rendererObject);
                        GenerateHarmonyMeta.CreateOrUpdateAnchorsFromMetadata(rendererObject);
                        GenerateHarmonyMeta.CreateOrUpdateGenericMetadata(rendererObject);
                    }

                    serializedObject.Update();
                }

                EditorGUILayout.EndHorizontal();
            }

            --EditorGUI.indentLevel;

            //  Restore label width...
            EditorGUIUtility.labelWidth = 0f;
        }

        serializedObject.ApplyModifiedProperties();

        if (GUI.changed)
        {
            foreach (Object target in targetObjects)
            {
                EditorUtility.SetDirty(target);
            }
        }
    }
コード例 #27
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();

            var proCamera2D = (ProCamera2D)target;

            serializedObject.Update();


            EditorGUILayout.Space();

            // Draw User Guide link
            if (ProCamera2DEditorResources.UserGuideIcon != null)
            {
                var rect = GUILayoutUtility.GetRect(0f, 0f);
                rect.width  = ProCamera2DEditorResources.UserGuideIcon.width;
                rect.height = ProCamera2DEditorResources.UserGuideIcon.height;
                if (GUI.Button(new Rect(15, rect.y, 32, 32), new GUIContent(ProCamera2DEditorResources.UserGuideIcon, "User Guide")))
                {
                    Application.OpenURL("http://www.procamera2d.com/user-guide/");
                }
            }

            // Draw header
            if (ProCamera2DEditorResources.InspectorHeader != null)
            {
                var rect = GUILayoutUtility.GetRect(0f, 0f);
                rect.x     += 37;
                rect.width  = ProCamera2DEditorResources.InspectorHeader.width;
                rect.height = ProCamera2DEditorResources.InspectorHeader.height;
                GUILayout.Space(rect.height);
                GUI.DrawTexture(rect, ProCamera2DEditorResources.InspectorHeader);
            }

            EditorGUILayout.Space();


            // Review prompt
            if (_showReviewMessage)
            {
                EditorGUILayout.HelpBox("Sorry for the intrusion, but I need you for a second. Reviews on the Asset Store are very important for me to keep improving this product. Please take a minute to write a review and support ProCamera2D.", MessageType.Warning, true);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Sure, I'll write a review!"))
                {
                    _showReviewMessage = false;
                    EditorPrefs.SetInt("ProCamera2DReview", -1);
                    Application.OpenURL("http://u3d.as/i7L");
                }
                if (GUILayout.Button("No, thanks."))
                {
                    _showReviewMessage = false;
                    EditorPrefs.SetInt("ProCamera2DReview", -1);
                }
                EditorGUILayout.EndHorizontal();
                AddSpace();
            }


            // Assign game camera
            if (proCamera2D.GameCamera == null)
            {
                proCamera2D.GameCamera = proCamera2D.GetComponent <Camera>();
            }


            // Targets Drop Area
            Event evt       = Event.current;
            Rect  drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
            var   style     = new GUIStyle("box");

            if (EditorGUIUtility.isProSkin)
            {
                style.normal.textColor = Color.white;
            }
            GUI.Box(drop_area, "\nDROP CAMERA TARGETS HERE", style);

            Undo.RecordObject(proCamera2D, "Added camera targets");
            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!drop_area.Contains(evt.mousePosition))
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    foreach (Object dragged_object in DragAndDrop.objectReferences)
                    {
                        var newCameraTarget = new CameraTarget
                        {
                            TargetTransform = ((GameObject)dragged_object).transform,
                            TargetInfluence = 1f
                        };

                        proCamera2D.CameraTargets.Add(newCameraTarget);
                        EditorUtility.SetDirty(proCamera2D);
                    }
                }
                break;
            }

            EditorGUILayout.Space();



            // Remove empty targets
            for (int i = 0; i < proCamera2D.CameraTargets.Count; i++)
            {
                if (proCamera2D.CameraTargets[i].TargetTransform == null)
                {
                    proCamera2D.CameraTargets.RemoveAt(i);
                }
            }



            // Targets List
            _targetsList.DoLayoutList();
            AddSpace();



            // Center target on start
            _tooltip = new GUIContent("Center target on start", "Should the camera move instantly to the target on game start?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("CenterTargetOnStart"), _tooltip);

            AddSpace();



            // Axis
            _tooltip = new GUIContent("Axis", "Choose the axis in which the camera should move.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Axis"), _tooltip);

            AddSpace();



            // UpdateType
            _tooltip = new GUIContent("Update Type", "LateUpdate: Non physics based game\nFixedUpdate: Physics based game");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("UpdateType"), _tooltip);

            AddSpace();



            // Show correct axis name
            switch (proCamera2D.Axis)
            {
            case MovementAxis.XY:
                hAxis = "X";
                vAxis = "Y";
                break;

            case MovementAxis.XZ:
                hAxis = "X";
                vAxis = "Z";
                break;

            case MovementAxis.YZ:
                hAxis = "Y";
                vAxis = "Z";
                break;
            }



            // Follow horizontal
            EditorGUILayout.BeginHorizontal();
            _tooltip = new GUIContent("Follow " + hAxis, "Should the camera move on the horizontal axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FollowHorizontal"), _tooltip);
            if (proCamera2D.FollowHorizontal)
            {
                // Follow smoothness
                _tooltip = new GUIContent("Smoothness", "How long it takes the camera to reach the target horizontal position.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("HorizontalFollowSmoothness"), _tooltip);

                if (proCamera2D.HorizontalFollowSmoothness < 0f)
                {
                    proCamera2D.HorizontalFollowSmoothness = 0f;
                }
            }
            EditorGUILayout.EndHorizontal();


            // Follow vertical
            EditorGUILayout.BeginHorizontal();
            _tooltip = new GUIContent("Follow " + vAxis, "Should the camera move on the vertical axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("FollowVertical"), _tooltip);

            if (proCamera2D.FollowVertical)
            {
                // Follow smoothness
                _tooltip = new GUIContent("Smoothness", "How long it takes the camera to reach the target vertical position.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("VerticalFollowSmoothness"), _tooltip);

                if (proCamera2D.VerticalFollowSmoothness < 0f)
                {
                    proCamera2D.VerticalFollowSmoothness = 0f;
                }
            }
            EditorGUILayout.EndHorizontal();

            if (!proCamera2D.FollowHorizontal && !proCamera2D.FollowVertical)
            {
                EditorGUILayout.HelpBox("Camera won't move if it's not following the targets on any axis.", MessageType.Error, true);
            }

            AddSpace();



            // Overall offset
            EditorGUILayout.LabelField("Offset");
            EditorGUI.indentLevel = 1;

            if (proCamera2D.IsRelativeOffset)
            {
                _tooltip = new GUIContent(hAxis, "Horizontal offset");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("OffsetX"), _tooltip);

                _tooltip = new GUIContent(vAxis, "Vertical offset");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("OffsetY"), _tooltip);
            }
            else
            {
                _tooltip = new GUIContent(hAxis, "Horizontal offset");
                serializedObject.FindProperty("OffsetX").floatValue = EditorGUILayout.FloatField(hAxis, serializedObject.FindProperty("OffsetX").floatValue);

                _tooltip = new GUIContent(vAxis, "Vertical offset");
                serializedObject.FindProperty("OffsetY").floatValue = EditorGUILayout.FloatField(vAxis, serializedObject.FindProperty("OffsetY").floatValue);
            }

            _tooltip = new GUIContent("Relative Offset", "If enabled, the offset is relative to the current screen size. Otherwise it's in world units.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("IsRelativeOffset"), _tooltip);

            EditorGUI.indentLevel = 0;

            AddSpace();



            // Zoom with FOV
            if (!proCamera2D.GameCamera.orthographic)
            {
                GUI.enabled = !Application.isPlaying;
                _tooltip    = new GUIContent("Zoom With FOV", "If enabled, when using a perspective camera, the camera will zoom by changing the FOV instead of moving the camera closer/further from the objects.");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("ZoomWithFOV"), _tooltip);
                GUI.enabled = true;
                AddSpace();
            }



            // Ignore TimeScale
            _tooltip = new GUIContent("Ignore TimeScale", "If enabled, the camera will not be affected by the Time.timeScale. It will use Time.unscaledDeltaTime instead.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("IgnoreTimeScale"), _tooltip);
            AddSpace();



            // Divider
            GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
            GUILayout.Label("EXTENSIONS", EditorStyles.boldLabel);
            EditorGUILayout.Space();


            // Extensions
            GUI.color = Color.white;
            for (int i = 0; i < _extensions.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField(_extensions[i].ExtName);
                if (_extensions[i].Component == null)
                {
                    GUI.color = new Color(133f / 255f, 235f / 255f, 154f / 255f, 1f);
                    if (GUILayout.Button("Enable"))
                    {
                        _extensions[i].Component = proCamera2D.gameObject.AddComponent(_extensions[i].ExtType) as BasePC2D;
                    }
                }
                else
                {
                    GUI.color = new Color(236f / 255f, 72f / 255f, 105f / 255f, 1f);
                    if (GUILayout.Button("Disable"))
                    {
                        if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to remove this extension?", "Yes", "No"))
                        {
                            DestroyImmediate(_extensions[i].Component);
                            EditorGUIUtility.ExitGUI();
                        }
                    }
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
            }



            // Divider
            EditorGUILayout.Space();
            GUI.color = Color.white;
            GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
            GUILayout.Label("TRIGGERS", EditorStyles.boldLabel);
            EditorGUILayout.Space();


            // Triggers
            for (int i = 0; i < _triggers.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField(_triggers[i].TriggerName + " (" + _triggers[i].AllTriggers.Count() + ")");

                if (GUILayout.Button("Add"))
                {
                    var newGo = new GameObject(_triggers[i].TriggerType.Name);
                    newGo.transform.localScale = new Vector3(5, 5, 5);
                    var trigger = newGo.AddComponent(_triggers[i].TriggerType) as BasePC2D;
                    _triggers[i].AllTriggers.Add(trigger);
                }

                GUI.enabled = _triggers[i].AllTriggers.Count() > 0;

                if (GUILayout.Button(">"))
                {
                    Selection.activeGameObject = ((BasePC2D)_triggers[i].AllTriggers[_triggers[i].TriggerCurrentIndex]).gameObject;
                    SceneView.FrameLastActiveSceneView();
                    EditorGUIUtility.PingObject(((BasePC2D)_triggers[i].AllTriggers[_triggers[i].TriggerCurrentIndex]).gameObject);

                    Selection.activeGameObject = proCamera2D.gameObject;

                    _triggers[i].TriggerCurrentIndex = _triggers[i].TriggerCurrentIndex >= _triggers[i].AllTriggers.Count - 1 ? 0 : _triggers[i].TriggerCurrentIndex + 1;
                }

                GUI.enabled = true;

                EditorGUILayout.EndHorizontal();
            }

            AddSpace();


            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(proCamera2D);
            }
        }
コード例 #28
0
ファイル: StyleModule.cs プロジェクト: hansanjie/AI4Animation
    protected override void DerivedInspector(MotionEditor editor)
    {
        Repair();

        Frame frame = editor.GetCurrentFrame();

        if (Utility.GUIButton("Key", IsKey(frame) ? UltiDraw.Cyan : UltiDraw.DarkGrey, IsKey(frame) ? UltiDraw.Black : UltiDraw.White))
        {
            ToggleKey(frame);
        }
        Color[] colors = UltiDraw.GetRainbowColors(Functions.Length);
        for (int i = 0; i < Functions.Length; i++)
        {
            float height = 25f;
            EditorGUILayout.BeginHorizontal();
            if (Utility.GUIButton(Functions[i].Name, colors[i].Transparent(Utility.Normalise(Functions[i].GetValue(frame), 0f, 1f, 0.25f, 1f)), UltiDraw.White, 200f, height))
            {
                Functions[i].Toggle(frame);
            }
            //EditorGUILayout.Toggle(Functions[i].GetFlag(frame));
            //EditorGUILayout.Toggle(Functions[i].GetRelease(frame));
            Rect c = EditorGUILayout.GetControlRect();
            Rect r = new Rect(c.x, c.y, Functions[i].GetValue(frame) * c.width, height);
            EditorGUI.DrawRect(r, colors[i].Transparent(0.75f));
            EditorGUILayout.FloatField(Functions[i].GetValue(frame), GUILayout.Width(50f));
            Functions[i].Name = EditorGUILayout.TextField(Functions[i].Name);
            if (Utility.GUIButton("X", UltiDraw.DarkRed, UltiDraw.White, 20f, 20f))
            {
                RemoveStyle(Functions[i].Name);
            }
            EditorGUILayout.EndHorizontal();
        }
        if (Utility.GUIButton("Add Style", UltiDraw.DarkGrey, UltiDraw.White))
        {
            AddStyle("Style " + (Functions.Length + 1));
            EditorGUIUtility.ExitGUI();
        }
        EditorGUILayout.BeginHorizontal();
        if (Utility.GUIButton("<", UltiDraw.DarkGrey, UltiDraw.White, 25f, 50f))
        {
            Frame previous = GetPreviousKey(frame);
            editor.LoadFrame(previous == null ? 0f : previous.Timestamp);
        }
        EditorGUILayout.BeginVertical(GUILayout.Height(50f));
        Rect ctrl = EditorGUILayout.GetControlRect();
        Rect rect = new Rect(ctrl.x, ctrl.y, ctrl.width, 50f);

        EditorGUI.DrawRect(rect, UltiDraw.Black);

        UltiDraw.Begin();

        float startTime = frame.Timestamp - editor.GetWindow() / 2f;
        float endTime   = frame.Timestamp + editor.GetWindow() / 2f;

        if (startTime < 0f)
        {
            endTime  -= startTime;
            startTime = 0f;
        }
        if (endTime > Data.GetTotalTime())
        {
            startTime -= endTime - Data.GetTotalTime();
            endTime    = Data.GetTotalTime();
        }
        startTime = Mathf.Max(0f, startTime);
        endTime   = Mathf.Min(Data.GetTotalTime(), endTime);
        int start    = Data.GetFrame(startTime).Index;
        int end      = Data.GetFrame(endTime).Index;
        int elements = end - start;

        Vector3 prevPos = Vector3.zero;
        Vector3 newPos  = Vector3.zero;
        Vector3 bottom  = new Vector3(0f, rect.yMax, 0f);
        Vector3 top     = new Vector3(0f, rect.yMax - rect.height, 0f);

        //Sequences
        for (int i = 0; i < Data.Sequences.Length; i++)
        {
            float   _start = (float)(Mathf.Clamp(Data.Sequences[i].Start, start, end) - start) / (float)elements;
            float   _end   = (float)(Mathf.Clamp(Data.Sequences[i].End, start, end) - start) / (float)elements;
            float   left   = rect.x + _start * rect.width;
            float   right  = rect.x + _end * rect.width;
            Vector3 a      = new Vector3(left, rect.y, 0f);
            Vector3 b      = new Vector3(right, rect.y, 0f);
            Vector3 c      = new Vector3(left, rect.y + rect.height, 0f);
            Vector3 d      = new Vector3(right, rect.y + rect.height, 0f);
            UltiDraw.DrawTriangle(a, c, b, UltiDraw.Yellow.Transparent(0.25f));
            UltiDraw.DrawTriangle(b, c, d, UltiDraw.Yellow.Transparent(0.25f));
        }

        //Styles
        for (int i = 0; i < Functions.Length; i++)
        {
            Frame current = Data.GetFirstFrame();
            while (current != Data.GetLastFrame())
            {
                Frame next   = GetNextKey(current);
                float _start = (float)(Mathf.Clamp(current.Index, start, end) - start) / (float)elements;
                float _end   = (float)(Mathf.Clamp(next.Index, start, end) - start) / (float)elements;
                float xStart = rect.x + _start * rect.width;
                float xEnd   = rect.x + _end * rect.width;
                float yStart = rect.y + (1f - Functions[i].Values[Mathf.Clamp(current.Index, start, end) - 1]) * rect.height;
                float yEnd   = rect.y + (1f - Functions[i].Values[Mathf.Clamp(next.Index, start, end) - 1]) * rect.height;
                UltiDraw.DrawLine(new Vector3(xStart, yStart, 0f), new Vector3(xEnd, yEnd, 0f), colors[i]);
                current = next;
            }
        }

        //Keys
        for (int i = 0; i < Keys.Length; i++)
        {
            if (Keys[i])
            {
                top.x    = rect.xMin + (float)(i + 1 - start) / elements * rect.width;
                bottom.x = rect.xMin + (float)(i + 1 - start) / elements * rect.width;
                UltiDraw.DrawLine(top, bottom, UltiDraw.White);
            }
        }

        //Current Pivot
        top.x    = rect.xMin + (float)(frame.Index - start) / elements * rect.width;
        bottom.x = rect.xMin + (float)(frame.Index - start) / elements * rect.width;
        UltiDraw.DrawLine(top, bottom, UltiDraw.Yellow);
        UltiDraw.DrawCircle(top, 3f, UltiDraw.Green);
        UltiDraw.DrawCircle(bottom, 3f, UltiDraw.Green);

        UltiDraw.End();
        EditorGUILayout.EndVertical();
        if (Utility.GUIButton(">", UltiDraw.DarkGrey, UltiDraw.White, 25f, 50f))
        {
            Frame next = GetNextKey(frame);
            editor.LoadFrame(next == null ? Data.GetTotalTime() : next.Timestamp);
        }
        EditorGUILayout.EndHorizontal();
    }
コード例 #29
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            Rect r = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);

            r.width -= EditorGUIUtility.labelWidth;

            EditorGUI.PrefixLabel(r, new GUIContent("Frame Rate"));

            r.width += EditorGUIUtility.labelWidth;

            EditorGUI.BeginChangeCheck();
            r.xMin += EditorGUIUtility.labelWidth;

            int frameRate = FGUI.FrameRatePopup(r, _sequence.FrameRate);

            if (EditorGUI.EndChangeCheck())
            {
                if (frameRate == -1)
                {
                    FChangeFrameRateWindow.Show(new Vector2(r.xMin - EditorGUIUtility.labelWidth, r.yMax), _sequence, FSequenceInspector.Rescale);
                    EditorGUIUtility.ExitGUI();
                }
                else
                {
                    Rescale(_sequence, frameRate, true);
                }
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Open In Flux Editor"))
            {
                FSequenceEditorWindow.Open(_sequence);
            }

            EditorGUILayout.Space();

            if (GUILayout.Button(_advancedInspector ? "Normal Inspector" : "Advanced Inspector"))
            {
                _advancedInspector = !_advancedInspector;
            }

            if (_advancedInspector)
            {
                EditorGUILayout.PropertyField(_timelineContainer);

                EditorGUI.BeginChangeCheck();
                bool showTimelines = EditorGUILayout.Toggle("Show Timelines", (_timelineContainer.objectReferenceValue.hideFlags & HideFlags.HideInHierarchy) == 0);
                if (EditorGUI.EndChangeCheck())
                {
                    if (showTimelines)
                    {
                        _timelineContainer.objectReferenceValue.hideFlags &= ~HideFlags.HideInHierarchy;
                    }
                    else
                    {
                        _timelineContainer.objectReferenceValue.hideFlags |= HideFlags.HideInHierarchy;
                    }
                }
            }

//			if( GUILayout.Button("Play") )
//				_sequence.Play();
        }
コード例 #30
0
        void OnGUI()
        {
            if (WMSK.instance == null)
            {
                DestroyImmediate(this);
                EditorGUIUtility.ExitGUI();
                return;
            }

            if (countryIndex >= 0)
            {
                EditorGUILayout.HelpBox("This option will merge provinces of " + WMSK.instance.countries [countryIndex].name + " producing a number of provinces in the range below. The final number of provinces will be randomly chosen according to this range.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("This option will merge provinces of each country producing a number of provinces in the range below. The final number of provinces of each country will be randomly chosen according to this range.", MessageType.Info);
            }
            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Minimum", GUILayout.Width(80));
            provincesMin = EditorGUILayout.IntSlider(provincesMin, 1, 40);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Maximum", GUILayout.Width(80));
            provincesMax = EditorGUILayout.IntSlider(provincesMax, 1, 40);
            EditorGUILayout.EndHorizontal();
            if (provincesMax < provincesMin)
            {
                provincesMax = provincesMin;
            }
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            if (started)
            {
                EditorGUILayout.HelpBox("This operation can take some time. Please wait until it finishes. Processing .... " + currentCountryIndex + "/" + countryCount, MessageType.Warning);
            }
            else
            {
                EditorGUILayout.HelpBox("This operation can take some time. Please wait until it finishes.", MessageType.Warning);
            }
            if (started)
            {
                GUI.enabled = false;
                GUILayout.Button("Busy...");
                GUI.enabled = true;
            }
            else
            {
                if (GUILayout.Button("Start"))
                {
                    WMSK.instance.showProvinces    = true;
                    WMSK.instance.drawAllProvinces = true;
                    WMSK.instance.editor.ClearSelection();
                    started = true;
                }
            }
            if (GUILayout.Button("Cancel"))
            {
                started = false;
                Close();
            }
        }