예제 #1
0
    private void OnDestroy()
    {
        if (renderCamera != null)
        {
            DestroyImmediate(renderCamera.gameObject);
        }

        if (modelInst != null)
        {
            DestroyImmediate(modelInst);
        }

        if (previewTexture != null)
        {
            DestroyImmediate(previewTexture);
        }

        EditorPrefs.SetString("SG_Directory", directory);
        EditorPrefs.SetInt("SG_ResolutionX", imageResolutionX);
        EditorPrefs.SetInt("SG_ResolutionY", imageResolutionY);
        EditorPrefs.SetBool("SG_Perspective", perspectiveMode);
        EditorPrefs.SetFloat("SG_FieldOfView", fieldOfView);
        EditorPrefs.SetFloat("SG_OrthoSize", orthoSize);
    }
        public static void Save()
        {
            EditorPrefs.SetBool("LockAxisX", AxisLockX);
            EditorPrefs.SetBool("LockAxisY", AxisLockY);
            EditorPrefs.SetBool("LockAxisZ", AxisLockZ);

            EditorPrefs.SetBool("BoundsSnapping", BoundsSnapping);
            EditorPrefs.SetBool("PivotSnapping", PivotSnapping);
            EditorPrefs.SetBool("UniformGrid", !ShowAllAxi);
            EditorPrefs.SetFloat("MoveSnapX", MoveSnapX);
            EditorPrefs.SetFloat("MoveSnapY", MoveSnapY);
            EditorPrefs.SetFloat("MoveSnapZ", MoveSnapZ);

            EditorPrefs.SetInt("DistanceUnit", (int)DistanceUnit);

            EditorPrefs.SetBool("RotateSnapping", RotateSnapping);
            EditorPrefs.SetFloat("RotationSnap", RotateSnap);

            EditorPrefs.SetBool("ScaleSnapping", ScaleSnapping);
            EditorPrefs.SetFloat("ScaleSnap", ScaleSnap);

            EditorPrefs.SetBool("ShowGrid", ShowGrid);
            EditorPrefs.SetInt("CSGEditMode", (int)EditMode);
        }
예제 #3
0
        public static void HandlePreferencesGUI(SerializedObject settings)
        {
            float prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 250;

            using (new EditorGUI.IndentLevelScope()) {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(settings.FindProperty("showHierarchyIcons"), new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes."));
                if (EditorGUI.EndChangeCheck())
                {
                                        #if NEWPLAYMODECALLBACKS
                    SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
                                        #else
                    SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged();
                                        #endif
                }

                EditorGUILayout.PropertyField(settings.FindProperty("autoReloadSceneSkeletons"), new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."));

                EditorGUILayout.Separator();
                EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.FloatPropertyField(settings.FindProperty("defaultMix"), new GUIContent("Default Mix", "The Default Mix Duration for newly imported SkeletonDataAssets."), min: 0f);
                    SpineEditorUtilities.FloatPropertyField(settings.FindProperty("defaultScale"), new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);

                    SpineEditorUtilities.ShaderPropertyField(settings.FindProperty("defaultShader"), new GUIContent("Default Shader"), SpinePreferences.DEFAULT_DEFAULT_SHADER);

                    EditorGUILayout.PropertyField(settings.FindProperty("setTextureImporterSettings"), new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Warnings", EditorStyles.boldLabel);
                {
                    EditorGUILayout.PropertyField(settings.FindProperty("atlasTxtImportWarning"), new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found."));
                    EditorGUILayout.PropertyField(settings.FindProperty("textureImporterWarning"), new GUIContent("Texture Settings Warning", "Log a warning and recommendation whenever Texture Import Settings are detected that could lead to undesired effects, e.g. white border artifacts."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
                {
                    EditorGUILayout.Slider(settings.FindProperty("defaultZSpacing"), -0.1f, 0f, new GUIContent("Default Slot Z-Spacing"));
                    EditorGUILayout.PropertyField(settings.FindProperty("defaultInstantiateLoop"), new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    SpineHandles.handleScale = EditorGUILayout.Slider("Editor Bone Scale", SpineHandles.handleScale, 0.01f, 2f);
                    SpineHandles.handleScale = Mathf.Max(0.01f, SpineHandles.handleScale);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(SpinePreferences.SCENE_ICONS_SCALE_KEY, SpineHandles.handleScale);
                        SceneView.RepaintAll();
                    }
                }

                GUILayout.Space(20);
                EditorGUILayout.LabelField("3rd Party Settings", EditorStyles.boldLabel);
                using (new GUILayout.HorizontalScope()) {
                    EditorGUILayout.PrefixLabel("Define TK2D");
                    if (GUILayout.Button("Enable", GUILayout.Width(64)))
                    {
                        SpineEditorUtilities.SpineTK2DEditorUtility.EnableTK2D();
                    }
                    if (GUILayout.Button("Disable", GUILayout.Width(64)))
                    {
                        SpineEditorUtilities.SpineTK2DEditorUtility.DisableTK2D();
                    }
                }
            }
            EditorGUIUtility.labelWidth = prevLabelWidth;
        }
        void OnGUI()
        {
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (markerType == 0)
            {
                GUILayout.Label("Editing Default Phoneme Marker");
            }
            else
            {
                GUILayout.Label("Editing Default Emotion Marker");
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            scrollPosition      = EditorGUILayout.BeginScrollView(scrollPosition);
            intensity           = EditorGUILayout.Slider("Intensity", intensity, 0, 1);
            modifierOn          = EditorGUILayout.Toggle(markerType == 0 ? "Use Randomess" : "Use Continuous Variation", modifierOn);
            modifierBool.target = modifierOn;
            if (EditorGUILayout.BeginFadeGroup(modifierBool.faded))
            {
                if (markerType == 1)
                {
                    GUILayout.BeginHorizontal();
                    maxVariationFrequency = EditorGUILayout.Slider("Vary every:", maxVariationFrequency, 0.2f, 3);
                    GUILayout.Label(" seconds");
                    GUILayout.EndHorizontal();
                }
                intensityModifier    = EditorGUILayout.Slider(markerType == 0 ? "Intensity Randomness" : "Intensity Variation", intensityModifier, 0, 1);
                blendableModifier    = EditorGUILayout.Slider(markerType == 0 ? "Blendable Value Randomness" : "Blendable Value Variation", blendableModifier, 0, 1);
                bonePositionModifier = EditorGUILayout.Slider(markerType == 0 ? "Bone Position Randomness" : "Bone Position Variation", bonePositionModifier, 0, 1);
                boneRotationModifier = EditorGUILayout.Slider(markerType == 0 ? "Bone Rotation Randomness" : "Bone Rotation Variation", boneRotationModifier, 0, 1);
            }
            EditorGUILayout.EndFadeGroup();
            EditorGUILayout.EndScrollView();
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Accept", GUILayout.MinWidth(100), GUILayout.Height(20)))
            {
                if (markerType == 0)
                {
                    EditorPrefs.SetFloat("LipSync_DefaultPhonemeIntensity", intensity);
                    EditorPrefs.SetBool("LipSync_DefaultUseRandomness", modifierOn);
                    EditorPrefs.SetFloat("LipSync_DefaultIntensityRandomness", intensityModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBlendableRandomness", blendableModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBonePositionRandomness", bonePositionModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBoneRotationRandomness", boneRotationModifier);

                    setup.defaultPhonemeIntensity       = intensity;
                    setup.defaultUseRandomness          = modifierOn;
                    setup.defaultIntensityRandomness    = intensityModifier;
                    setup.defaultBlendableRandomness    = blendableModifier;
                    setup.defaultBonePositionRandomness = bonePositionModifier;
                    setup.defaultBoneRotationRandomness = boneRotationModifier;
                }
                else
                {
                    EditorPrefs.SetFloat("LipSync_DefaultEmotionIntensity", intensity);
                    EditorPrefs.SetBool("LipSync_DefaultContinuousVariation", modifierOn);
                    EditorPrefs.SetFloat("LipSync_DefaultVariationFrequency", maxVariationFrequency);
                    EditorPrefs.SetFloat("LipSync_DefaultIntensityVariation", intensityModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBlendableVariation", blendableModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBonePositionVariation", bonePositionModifier);
                    EditorPrefs.SetFloat("LipSync_DefaultBoneRotationVariation", boneRotationModifier);

                    setup.defaultEmotionIntensity      = intensity;
                    setup.defaultUseRandomness         = modifierOn;
                    setup.defaultVariationFrequency    = maxVariationFrequency;
                    setup.defaultIntensityVariation    = intensityModifier;
                    setup.defaultBlendableVariation    = blendableModifier;
                    setup.defaultBonePositionVariation = bonePositionModifier;
                    setup.defaultBoneRotationVariation = boneRotationModifier;
                }

                Close();
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Cancel", GUILayout.MinWidth(100), GUILayout.Height(20)))
            {
                Close();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(20);
        }
예제 #5
0
        public static void SaveFloat(SF_Setting setting, float value)
        {
            string key = KeyOf(setting);

            EditorPrefs.SetFloat(key, value);
        }
예제 #6
0
    private void CountLines()
    {
        directory  = Directory.GetCurrentDirectory();
        directory += directoryToCheck;
        fileStats  = new List <File>();
        ProcessDirectory(fileStats, directory);

        totalLines = 0;
        foreach (File f in fileStats)
        {
            totalLines += f.numLines;
        }

        int scriptCountDelta = (fileStats.Count - EditorPrefs.GetInt("LC_OldScriptCount_" + PlayerSettings.productName, 0));
        int totalLineDelta   = (totalLines - EditorPrefs.GetInt("LC_OldTotalLines_" + PlayerSettings.productName, 0));

        stringStats = new StringBuilder();
        stringStats.Append("Total Number of Scripts: " + fileStats.Count + ((scriptCountDelta != 0) ? "   [" + ((scriptCountDelta > 0) ? "+" : "") + scriptCountDelta.ToString() + " script(s)]" : "") + "\n");
        stringStats.Append("Total Number of Lines: " + totalLines + ((totalLineDelta != 0) ? "   [" + ((totalLineDelta > 0) ? "+" : "") + totalLineDelta.ToString() + " line(s)]" : "") + "\n");

        averageLines = Mathf.Round(totalLines * 10f / fileStats.Count) / 10f;
        float avgLineDelta = (averageLines - EditorPrefs.GetFloat("LC_OldAvgLines_" + PlayerSettings.productName, 0f));

        stringStats.Append("Averages Lines per Script: " + averageLines.ToString("F1") + " lines " + ((avgLineDelta != 0f) ? "   [" + ((avgLineDelta > 0f) ? "+" : "") + avgLineDelta.ToString("F1") + " avg line(s)]" : ""));

        if (sortMethod == SortMethod.LineCount)
        {
            fileStats.Sort((f1, f2) => f2.numLines.CompareTo(f1.numLines));
        }
        else if (sortMethod == SortMethod.Alphabetical)
        {
            fileStats.Sort((f1, f2) => f1.displayName.CompareTo(f2.displayName));
        }

        largestLineCountRef = new File();
        if (fileStats.Count > 0)
        {
            if (sortMethod == SortMethod.LineCount)
            {
                largestLineCountRef = fileStats[0];
            }
            else if (sortMethod == SortMethod.Alphabetical)
            {
                int largestLine = 0;
                for (int i = 0; i < fileStats.Count; i++)
                {
                    if (fileStats[i].numLines > largestLine)
                    {
                        largestLineCountRef = fileStats[i];
                        largestLine         = fileStats[i].numLines;
                    }
                }
            }
        }

        Repaint();

        EditorPrefs.SetInt("LC_OldScriptCount_" + PlayerSettings.productName, fileStats.Count);
        EditorPrefs.SetInt("LC_OldTotalLines_" + PlayerSettings.productName, totalLines);
        EditorPrefs.SetFloat("LC_OldAvgLines_" + PlayerSettings.productName, averageLines);
    }
예제 #7
0
        public static void HandlePreferencesGUI(SerializedObject settings)
        {
            float prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 250;

            using (new EditorGUI.IndentLevelScope()) {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(settings.FindProperty("showHierarchyIcons"), new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes."));
                if (EditorGUI.EndChangeCheck())
                {
#if NEWPLAYMODECALLBACKS
                    SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
#else
                    SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged();
#endif
                }

                EditorGUILayout.PropertyField(settings.FindProperty("autoReloadSceneSkeletons"), new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."));

                EditorGUILayout.Separator();
                EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.FloatPropertyField(settings.FindProperty("defaultMix"), new GUIContent("Default Mix", "The Default Mix Duration for newly imported SkeletonDataAssets."), min: 0f);
                    SpineEditorUtilities.FloatPropertyField(settings.FindProperty("defaultScale"), new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);

                    SpineEditorUtilities.ShaderPropertyField(settings.FindProperty("defaultShader"), new GUIContent("Default Shader"), SpinePreferences.DEFAULT_DEFAULT_SHADER);

                    EditorGUILayout.PropertyField(settings.FindProperty("setTextureImporterSettings"), new GUIContent("Apply Atlas Texture Settings", "Apply reference settings for Texture Importers."));
                    var textureSettingsRef = settings.FindProperty("textureSettingsReference");
                    SpineEditorUtilities.PresetAssetPropertyField(textureSettingsRef, new GUIContent("Atlas Texture Settings", "Apply the selected texture import settings at newly imported atlas textures. When exporting atlas textures from Spine with \"Premultiply alpha\" enabled (the default), you can leave it at \"PMATexturePreset\". If you have disabled \"Premultiply alpha\", set it to \"StraightAlphaTexturePreset\". You can also create your own TextureImporter Preset asset and assign it here."));
                    if (string.IsNullOrEmpty(textureSettingsRef.stringValue))
                    {
                        var pmaTextureSettingsReferenceGUIDS = AssetDatabase.FindAssets("PMATexturePreset");
                        if (pmaTextureSettingsReferenceGUIDS.Length > 0)
                        {
                            textureSettingsRef.stringValue = AssetDatabase.GUIDToAssetPath(pmaTextureSettingsReferenceGUIDS[0]);
                        }
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Warnings", EditorStyles.boldLabel);
                {
                    EditorGUILayout.PropertyField(settings.FindProperty("atlasTxtImportWarning"), new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found."));
                    EditorGUILayout.PropertyField(settings.FindProperty("textureImporterWarning"), new GUIContent("Texture Settings Warning", "Log a warning and recommendation whenever Texture Import Settings are detected that could lead to undesired effects, e.g. white border artifacts."));
                    EditorGUILayout.PropertyField(settings.FindProperty("componentMaterialWarning"), new GUIContent("Component & Material Warning", "Log a warning and recommendation whenever Component and Material settings are not compatible."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
                {
                    EditorGUILayout.Slider(settings.FindProperty("defaultZSpacing"), -0.1f, 0f, new GUIContent("Default Slot Z-Spacing"));
                    EditorGUILayout.PropertyField(settings.FindProperty("defaultInstantiateLoop"), new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Mecanim Bake Settings", EditorStyles.boldLabel);
                {
                    EditorGUILayout.PropertyField(settings.FindProperty("mecanimEventIncludeFolderName"), new GUIContent("Include Folder Name in Event", "When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    var scaleProperty = settings.FindProperty("handleScale");
                    EditorGUILayout.PropertyField(scaleProperty, new GUIContent("Editor Bone Scale"));
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(SpinePreferences.SCENE_ICONS_SCALE_KEY, scaleProperty.floatValue);
                        SceneView.RepaintAll();
                    }
                }

                                #if SPINE_TK2D_DEFINE
                bool isTK2DDefineSet = true;
                                #else
                bool isTK2DDefineSet = false;
                                #endif
                bool isTK2DAllowed = SpineEditorUtilities.SpineTK2DEditorUtility.IsTK2DAllowed;
                if (SpineEditorUtilities.SpineTK2DEditorUtility.IsTK2DInstalled() || isTK2DDefineSet)
                {
                    GUILayout.Space(20);
                    EditorGUILayout.LabelField("3rd Party Settings", EditorStyles.boldLabel);
                    using (new GUILayout.HorizontalScope()) {
                        EditorGUILayout.PrefixLabel("Define TK2D");
                        if (isTK2DAllowed && GUILayout.Button("Enable", GUILayout.Width(64)))
                        {
                            SpineEditorUtilities.SpineTK2DEditorUtility.EnableTK2D();
                        }
                        if (GUILayout.Button("Disable", GUILayout.Width(64)))
                        {
                            SpineEditorUtilities.SpineTK2DEditorUtility.DisableTK2D();
                        }
                    }
                                        #if !SPINE_TK2D_DEFINE
                    if (!isTK2DAllowed)
                    {
                        EditorGUILayout.LabelField("To allow TK2D support, please modify line 67 in", EditorStyles.boldLabel);
                        EditorGUILayout.LabelField("Spine/Editor/spine-unity/Editor/Util./BuildSettings.cs", EditorStyles.boldLabel);
                    }
                                        #endif
                }

                GUILayout.Space(20);
                EditorGUILayout.LabelField("Timeline Extension", EditorStyles.boldLabel);
                {
                    EditorGUILayout.PropertyField(settings.FindProperty("timelineUseBlendDuration"), new GUIContent("Use Blend Duration", "When enabled, MixDuration will be synced with timeline clip transition duration 'Ease In Duration'."));
                }
            }
            EditorGUIUtility.labelWidth = prevLabelWidth;
        }
예제 #8
0
    void OnGUI()
    {
        EditorStyles.label.wordWrap = true;

        EditorGUILayout.BeginHorizontal();
        GUI.color    = Color.yellow;
        saveExternal = EditorGUILayout.Toggle("Save to External Directory?", saveExternal);
        EditorGUILayout.EndHorizontal();

        if (saveExternal)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("Save Directory", saveDirectory);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.green;
            var chooseDirectory = GUILayout.Button("Choose Directory");
            EditorGUILayout.EndHorizontal();

            if (chooseDirectory)
            {
                saveDirectory = EditorUtility.SaveFolderPanel("Select Directory", "", "");
            }
        }

        EditorGUILayout.BeginHorizontal();
        GUI.color   = Color.yellow;
        recalcNorms = EditorGUILayout.Toggle("Fix Normals(slow)", recalcNorms);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.color    = Color.yellow;
        recalcBounds = EditorGUILayout.Toggle("Fix Bounds(slower)", recalcBounds);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.color   = Color.yellow;
        exportScale = EditorGUILayout.FloatField("Export Scale", exportScale);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.color = Color.cyan;
        EditorGUILayout.LabelField("Normal Export Scale for Unity is 100. This May Be Adjusted for other 3D Software.");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.color    = Color.green;
        saveSettings = GUILayout.Button("Save");
        EditorGUILayout.EndHorizontal();

        if (saveSettings)
        {
            EditorPrefs.SetBool("RecalcNormals", recalcNorms);
            EditorPrefs.SetBool("RecalcBounds", recalcBounds);
            EditorPrefs.SetFloat("ExportScale", exportScale);
            EditorPrefs.SetBool("SaveExternal", saveExternal);
            EditorPrefs.SetString("SaveDirectory", saveDirectory);
            owindow.Close();
        }
    }
예제 #9
0
 public void setFloat(string name, float value)
 {
     EditorPrefs.SetFloat(name, value);
 }
예제 #10
0
 public static void ApplyTime()
 {
     EditorPrefs.SetFloat("ME.ECS.Generator.lastGenTime", (float)EditorApplication.timeSinceStartup);
 }
예제 #11
0
 // FLOAT
 public static void SetFloat(string settingPath, float value)
 {
     EditorPrefs.SetFloat(settingPath + ".float", value);
 }
예제 #12
0
    void OnGUI()
    {
        string path  = ("Assets/Puppet2D/Textures/GUI/BoneNoJoint.psd");
        string path2 = ("Assets/Puppet2D/Textures/GUI/BoneScaled.psd");
        string path3 = ("Assets/Puppet2D/Textures/GUI/BoneJoint.psd");
        string path4 = ("Assets/Puppet2D/Textures/GUI/Bone.psd");

        boneNoJointSprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
        boneSprite        = AssetDatabase.LoadAssetAtPath(path2, typeof(Sprite)) as Sprite;
        boneHiddenSprite  = AssetDatabase.LoadAssetAtPath(path3, typeof(Sprite)) as Sprite;
        boneOriginal      = AssetDatabase.LoadAssetAtPath(path4, typeof(Sprite)) as Sprite;
        Texture aTexture         = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_Bones.png", typeof(Texture)) as Texture;
        Texture puppetManTexture = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_puppetman.png", typeof(Texture)) as Texture;
        Texture rigTexture       = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/GUI_Rig.png", typeof(Texture)) as Texture;
        Texture ControlTexture   = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/parentControl.psd", typeof(Texture)) as Texture;
        Texture VertexTexture    = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Textures/GUI/VertexHandle.psd", typeof(Texture)) as Texture;


        string[] sortingLayers = GetSortingLayerNames();
        Color    bgColor       = GUI.backgroundColor;

        if (currentGUIChoice == GUIChoice.BoneCreation)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(0, 0, 80, 20), "Skeleton"))
        {
            currentGUIChoice = GUIChoice.BoneCreation;
        }

        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.RigginSetup)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(80, 0, 80, 20), "Rigging"))
        {
            currentGUIChoice = GUIChoice.RigginSetup;
        }
        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.Skinning)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(160, 0, 80, 20), "Skinning"))
        {
            currentGUIChoice = GUIChoice.Skinning;
        }
        GUI.backgroundColor = bgColor;
        if (currentGUIChoice == GUIChoice.Animation)
        {
            GUI.backgroundColor = Color.green;
        }

        if (GUI.Button(new Rect(240, 0, 80, 20), "Animation"))
        {
            currentGUIChoice = GUIChoice.Animation;
        }
        GUI.backgroundColor = bgColor;

        if (EditSkinWeights || SplineCreation || FFDCreation)
        {
            GUI.backgroundColor = Color.grey;
        }


        GUI.DrawTexture(new Rect(25, 40, 32, 32), boneSprite.texture, ScaleMode.StretchToFill, true, 10.0F);

        EditorGUI.BeginChangeCheck();
        BoneSize = EditorGUI.Slider(new Rect(80, 40, 150, 20), BoneSize, 0F, 0.9999F);
        if (EditorGUI.EndChangeCheck())
        {
            ChangeBoneSize();
            EditorPrefs.SetFloat("Puppet2D_EditorBoneSize", BoneSize);
        }
        EditorGUI.BeginChangeCheck();
        _boneSortingIndex = EditorGUI.Popup(new Rect(80, 60, 150, 30), _boneSortingIndex, sortingLayers);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetInt("Puppet2D_BoneLayer", _boneSortingIndex);
        }
        if (sortingLayers.Length <= _boneSortingIndex)
        {
            _boneSortingIndex = 0;
            EditorPrefs.SetInt("Puppet2D_BoneLayer", _boneSortingIndex);
        }
        _boneSortingLayer = sortingLayers[_boneSortingIndex];


        GUI.DrawTexture(new Rect(25, 100, 32, 32), ControlTexture, ScaleMode.StretchToFill, true, 10.0F);

        EditorGUI.BeginChangeCheck();
        ControlSize = EditorGUI.Slider(new Rect(80, 100, 150, 20), ControlSize, 0F, .9999F);
        if (EditorGUI.EndChangeCheck())
        {
            ChangeControlSize();
            EditorPrefs.SetFloat("Puppet2D_EditorControlSize", ControlSize);
        }
        EditorGUI.BeginChangeCheck();
        _controlSortingIndex = EditorGUI.Popup(new Rect(80, 130, 150, 30), _controlSortingIndex, sortingLayers);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetInt("Puppet2D_ControlLayer", _controlSortingIndex);
        }
        if (sortingLayers.Length <= _controlSortingIndex)
        {
            _controlSortingIndex = 0;
            EditorPrefs.SetInt("Puppet2D_ControlLayer", _controlSortingIndex);
        }
        _controlSortingLayer = sortingLayers[_controlSortingIndex];


        GUI.DrawTexture(new Rect(15, 160, 275, 5), aTexture, ScaleMode.StretchToFill, true, 10.0F);

        int offsetControls = 130;

        if (currentGUIChoice == GUIChoice.BoneCreation)
        {
            //GUILayout.Label("Bone Creation", EditorStyles.boldLabel);

            GUILayout.Space(15);
            GUI.DrawTexture(new Rect(0, 60 + offsetControls, 64, 128), aTexture, ScaleMode.StretchToFill, true, 10.0F);
            GUILayout.Space(15);


            if (BoneCreation)
            {
                GUI.backgroundColor = Color.green;
            }


            if (GUI.Button(new Rect(80, 60 + offsetControls, 150, 30), "Create Bone Tool"))
            {
                BoneCreation      = true;
                currentActiveBone = null;
                EditorPrefs.SetBool("Puppet2D_BoneCreation", BoneCreation);
            }
            if (BoneCreation)
            {
                GUI.backgroundColor = bgColor;
            }


            if (GUI.Button(new Rect(80, 90 + offsetControls, 150, 30), "Finish Bone"))
            {
                Puppet2D_BoneCreation.BoneFinishCreation();
            }

            if (BoneCreation)
            {
                GUI.backgroundColor = Color.grey;
            }



            if (SplineCreation)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 150 + offsetControls, 150, 30), "Create Spline Tool"))
            {
                //Puppet2D_Spline.splineStoreData.FFDCtrls.Clear();
                //SplineCreation = true;
                Puppet2D_Spline.CreateSplineTool();
            }
            if (SplineCreation)
            {
                GUI.backgroundColor = bgColor;
            }
            numberSplineJoints = EditorGUI.IntSlider(new Rect(80, 190 + offsetControls, 150, 20), numberSplineJoints, 1, 10);

            if (GUI.Button(new Rect(80, 220 + offsetControls, 150, 30), "Finish Spline"))
            {
                Puppet2D_Spline.SplineFinishCreation();
            }
        }
        if (currentGUIChoice == GUIChoice.RigginSetup)
        {
            // GUILayout.Label("Rigging Setup", EditorStyles.boldLabel);

            GUI.DrawTexture(new Rect(0, 60 + offsetControls, 64, 128), rigTexture, ScaleMode.StretchToFill, true, 10.0F);
            if (GUI.Button(new Rect(80, 60 + offsetControls, 150, 30), "Create IK Control"))
            {
                Puppet2D_CreateControls.IKCreateTool();
            }
            if (GUI.Button(new Rect(80, 90 + offsetControls, 150, 30), "Create Parent Control"))
            {
                Puppet2D_CreateControls.CreateParentControl();
            }
            if (GUI.Button(new Rect(80, 120 + offsetControls, 150, 30), "Create Orient Control"))
            {
                Puppet2D_CreateControls.CreateOrientControl();
            }

            /*if (GUI.Button(new Rect(80, 160+offsetControls, 150, 30), "Create Avatar"))
             * {
             * Puppet2D_CreateControls.CreateAvatar();
             *
             * }*/
        }
        if (currentGUIChoice == GUIChoice.Skinning)
        {
            //GUILayout.Label("Skinning", EditorStyles.boldLabel);

            GUI.DrawTexture(new Rect(0, 50 + offsetControls, 64, 128), puppetManTexture, ScaleMode.StretchToFill, true, 10.0F);

            GUILayout.Space(55 + offsetControls);
            GUIStyle labelNew = EditorStyles.label;
            labelNew.alignment     = TextAnchor.LowerLeft;
            labelNew.contentOffset = new Vector2(80, 0);
            GUILayout.Label("Type of Mesh: ", labelNew);
            labelNew.contentOffset = new Vector2(0, 0);
            string[] TriangulationTypes = { "0", "1", "2", "3" };

            _triangulationIndex = EditorGUI.Popup(new Rect(180, 60 + offsetControls, 50, 30), _triangulationIndex, TriangulationTypes);


            if (GUI.Button(new Rect(80, 80 + offsetControls, 150, 30), "Convert Sprite To Mesh"))
            {
                Puppet2D_Skinning.ConvertSpriteToMesh(_triangulationIndex);
            }
            if (GUI.Button(new Rect(80, 110 + offsetControls, 150, 30), "Parent Object To Bones"))
            {
                Puppet2D_Skinning.BindRigidSkin();
            }
            GUILayout.Space(75);
            labelNew.alignment     = TextAnchor.LowerLeft;
            labelNew.contentOffset = new Vector2(80, 0);
            GUILayout.Label("Num Skin Bones: ", labelNew);
            labelNew.contentOffset = new Vector2(0, 0);
            string[] NumberBonesToSkinTo = { "1", "2", "4 (FFD)" };

            _numberBonesToSkinToIndex = EditorGUI.Popup(new Rect(180, 150 + offsetControls, 50, 30), _numberBonesToSkinToIndex, NumberBonesToSkinTo);

            if (GUI.Button(new Rect(80, 170 + offsetControls, 150, 30), "Bind Smooth Skin"))
            {
                Puppet2D_Skinning.BindSmoothSkin();
            }
            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = Color.green;
            }
            if (SkinWeightsPaint)
            {
                if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Manually Edit Weights"))
                {
                    // finish paint weights
                    Selection.activeGameObject = currentSelection;
                    if (currentSelection)
                    {
                        if (previousShader)
                        {
                            currentSelection.GetComponent <Renderer>().sharedMaterial.shader = previousShader;
                        }
                        SkinWeightsPaint = false;
                        if (previousVertColors != null && previousVertColors.Length > 0)
                        {
                            currentSelectionMesh.colors = previousVertColors;
                        }
                        currentSelectionMesh = null;
                        currentSelection     = null;
                        previousVertColors   = null;
                    }

                    EditSkinWeights = Puppet2D_Skinning.EditWeights();
                }
            }
            if (!SkinWeightsPaint)
            {
                if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Paint Weights"))
                {
                    if (EditSkinWeights)
                    {
                        EditSkinWeights = false;
                        Object[] bakedMeshes = Puppet2D_Skinning.FinishEditingWeights();

                        Selection.objects = bakedMeshes;
                    }

                    if (Selection.activeGameObject && Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>() && Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>().sharedMesh)
                    {
                        SkinWeightsPaint = true;
                        SkinnedMeshRenderer smr = Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>();
                        currentSelectionMesh = smr.sharedMesh;
                        currentSelection     = Selection.activeGameObject;
                        previousShader       = currentSelection.GetComponent <Renderer>().sharedMaterial.shader;
                        currentSelection.GetComponent <Renderer>().sharedMaterial.shader = Shader.Find("Puppet2D/vertColor");

                        if (currentSelectionMesh.colors.Length != currentSelectionMesh.vertices.Length)
                        {
                            currentSelectionMesh.colors = new Color[currentSelectionMesh.vertices.Length];
                            EditorUtility.SetDirty(currentSelection);
                            EditorUtility.SetDirty(currentSelectionMesh);
                            AssetDatabase.SaveAssets();
                            EditorApplication.SaveAssets();
                        }
                        else
                        {
                            previousVertColors = currentSelectionMesh.colors;
                        }
                        Selection.activeGameObject = smr.bones[0].gameObject;
                    }
                }
            }



            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = bgColor;
            }

            if (GUI.Button(new Rect(80, 230 + offsetControls, 150, 30), "Finish Edit Skin Weights"))
            {
                if (SkinWeightsPaint)
                {
                    if (currentSelection)
                    {
                        Selection.activeGameObject = currentSelection;

                        if (previousShader)
                        {
                            currentSelection.GetComponent <Renderer>().sharedMaterial.shader = previousShader;
                        }
                        SkinWeightsPaint = false;
                        if (previousVertColors != null && previousVertColors.Length > 0)
                        {
                            currentSelectionMesh.colors = previousVertColors;
                        }
                        currentSelectionMesh = null;
                        currentSelection     = null;
                        previousVertColors   = null;

                        Puppet2D_HiddenBone[] hiddenBones = Transform.FindObjectsOfType <Puppet2D_HiddenBone>();
                        foreach (Puppet2D_HiddenBone hiddenBone in hiddenBones)
                        {
                            hiddenBone.gameObject.GetComponent <SpriteRenderer>().color = Color.white;
                            if (hiddenBone.transform.parent != null)
                            {
                                hiddenBone.transform.parent.GetComponent <SpriteRenderer>().color = Color.white;
                            }
                        }
                    }
                    else
                    {
                        SkinWeightsPaint = false;
                    }
                }
                else
                {
                    EditSkinWeights = false;
                    Puppet2D_Skinning.FinishEditingWeights();
                }
            }
            float SkinWeightsPaintOffset = -80;

            if (EditSkinWeights)
            {
                SkinWeightsPaintOffset = -40;
                GUI.DrawTexture(new Rect(25, 260 + offsetControls, 32, 32), VertexTexture, ScaleMode.StretchToFill, true, 10.0F);
                EditorGUI.BeginChangeCheck();
                VertexHandleSize = EditorGUI.Slider(new Rect(80, 270 + offsetControls, 150, 20), VertexHandleSize, 0F, .9999F);
                if (EditorGUI.EndChangeCheck())
                {
                    ChangeVertexHandleSize();
                    EditorPrefs.SetFloat("Puppet2D_EditorVertexHandleSize", VertexHandleSize);
                }
            }
            if (SkinWeightsPaint)
            {
                SkinWeightsPaintOffset = -20;

                GUILayout.Space(offsetControls - 20);
                GUILayout.Label(" Brush Size", EditorStyles.boldLabel);
                EditSkinWeightRadius = EditorGUI.Slider(new Rect(80, 275 + offsetControls, 150, 20), EditSkinWeightRadius, 0F, 100F);
                GUILayout.Label(" Strength", EditorStyles.boldLabel);
                paintWeightsStrength = EditorGUI.Slider(new Rect(80, 295 + offsetControls, 150, 20), paintWeightsStrength, 0F, 1F);
            }

            if (EditSkinWeights || SkinWeightsPaint)
            {
                GUI.backgroundColor = Color.grey;
            }

            if (FFDCreation)
            {
                GUI.backgroundColor = Color.green;
            }

            if (GUI.Button(new Rect(80, 360 + offsetControls + SkinWeightsPaintOffset, 150, 30), "Create FFD Tool"))
            {
                if (!FFDCreation)
                {
                    FFDCreation = true;
                    if (Selection.activeGameObject && Selection.activeGameObject.GetComponent <SpriteRenderer>() && Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite&& !Selection.activeGameObject.GetComponent <SpriteRenderer>().sprite.name.Contains("bone"))
                    {
                        FFDGameObject = Selection.activeGameObject;
                    }
                    else
                    {
                        Debug.LogWarning("Need to select a sprite to make an FFD mesh, will create a dummy mesh instead");
                    }
                    Puppet2D_FFD.FFDSetFirstPath();
                }
            }
            if (FFDCreation)
            {
                GUI.backgroundColor = bgColor;
            }
            if (GUI.Button(new Rect(80, 390 + offsetControls + SkinWeightsPaintOffset, 150, 30), "Finish FFD"))
            {
                Puppet2D_FFD.FFDFinishCreation();
            }
        }
        if (currentGUIChoice == GUIChoice.Animation)
        {
            //GUILayout.Label("Animation", EditorStyles.boldLabel);

            if (GUI.Button(new Rect(80, 50 + offsetControls, 150, 30), "Bake Animation"))
            {
                Puppet2D_GlobalControl[] globalCtrlScripts = Transform.FindObjectsOfType <Puppet2D_GlobalControl>();
                for (int i = 0; i < globalCtrlScripts.Length; i++)
                {
                    Puppet2D_BakeAnimation BakeAnim = globalCtrlScripts[i].gameObject.AddComponent <Puppet2D_BakeAnimation>();
                    BakeAnim.Run();
                    DestroyImmediate(BakeAnim);
                    globalCtrlScripts[i].enabled = false;
                }
            }
            if (recordPngSequence && !ExportPngAlpha)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 100 + offsetControls, 150, 30), "Render Animation"))
            {
                checkPath = EditorUtility.SaveFilePanel("Choose Directory", pngSequPath, "exportedAnim", "");
                if (checkPath != "")
                {
                    pngSequPath       = checkPath;
                    recordPngSequence = true;
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
            }
            GUI.backgroundColor = bgColor;
            if (ExportPngAlpha)
            {
                GUI.backgroundColor = Color.green;
            }
            if (GUI.Button(new Rect(80, 130 + offsetControls, 150, 30), "Render Alpha"))
            {
                checkPath = EditorUtility.SaveFilePanel("Choose Directory", pngSequPath, "exportedAnim", "");
                if (checkPath != "")
                {
                    pngSequPath       = checkPath;
                    recordPngSequence = true;
                    ExportPngAlpha    = true;
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
            }
            if (ExportPngAlpha || recordPngSequence)
            {
                GUI.backgroundColor = bgColor;
            }
            if (GUI.Button(new Rect(80, 200 + offsetControls, 150, 30), "Save Selection"))
            {
                selectedControls.Add(new List <string>());
                selectedControlsData.Add(new List <string>());

                foreach (GameObject go in Selection.gameObjects)
                {
                    selectedControls[selectedControls.Count - 1].Add(Puppet2D_Selection.GetGameObjectPath(go));
                    selectedControlsData[selectedControlsData.Count - 1].Add(go.transform.localPosition.x + " " + go.transform.localPosition.y + " " + go.transform.localPosition.z + " " + go.transform.localRotation.x + " " + go.transform.localRotation.y + " " + go.transform.localRotation.z + " " + go.transform.localRotation.w + " " + go.transform.localScale.x + " " + go.transform.localScale.y + " " + go.transform.localScale.z + " ");
                }
                Puppet2D_Selection.SetSelectionString();
            }
            if (GUI.Button(new Rect(80, 230 + offsetControls, 150, 30), "Clear Selections"))
            {
                selectedControls.Clear();
                selectedControlsData.Clear();
                Puppet2D_Selection.SetSelectionString();
            }


            for (int i = 0; i < selectedControls.Count; i++)
            {
                int column = i % 3;
                int row    = 0;

                row = i / 3;
                Rect newLoadButtonPosition = new Rect(80 + (50 * column), 265 + offsetControls + row * 30, 50, 30);

                if (Event.current.type == EventType.ContextClick)
                {
                    Vector2 mousePos = Event.current.mousePosition;
                    if ((Event.current.button == 1) && newLoadButtonPosition.Contains(mousePos))
                    {
                        GenericMenu menu = new GenericMenu();

                        menu.AddItem(new GUIContent("Select Objects"), false, Puppet2D_Selection.SaveSelectionLoad, i);
                        menu.AddItem(new GUIContent("Remove Selection"), false, Puppet2D_Selection.SaveSelectionRemove, i);
                        menu.AddItem(new GUIContent("Append Selection"), false, Puppet2D_Selection.SaveSelectionAppend, i);
                        menu.AddItem(new GUIContent("Store Pose"), false, Puppet2D_Selection.StorePose, i);
                        menu.AddItem(new GUIContent("Load Pose"), false, Puppet2D_Selection.LoadPose, i);



                        menu.ShowAsContext();
                        Event.current.Use();
                    }
                }
                GUI.Box(newLoadButtonPosition, "Load");

                /*if (GUI.Button(newLoadButtonPosition, "Load"))
                 * {
                 *  Selection.objects = selectedControls[i].ToArray();
                 * }*/
            }
        }
    }
예제 #13
0
        public void OnGUI()
        {
            EditorGUILayout.HelpBox("Lightmap UVs are automatically generated.  This dialog controls how the UV2 channel is constructed.  Default values will work for most geometry, though if you are having difficulties with light blemishes this editor offers fine-grained control of the UV2 generation parameters.", MessageType.Warning);

            EditorGUI.showMixedValue = diff["angleError"];
            sampleAngleError         = EditorGUILayout.Slider("Angle Error", sampleAngleError, 1f, 75f);
            if (GUI.changed)
            {
                SetAngleError(sampleAngleError);  UpdateDiffDictionary(); RefreshUV2();  GUI.changed = false;
            }

            EditorGUI.showMixedValue = diff["areaError"];
            sampleAreaError          = EditorGUILayout.Slider("Area Error", sampleAreaError, 1f, 75f);
            if (GUI.changed)
            {
                SetAreaError(sampleAreaError);  UpdateDiffDictionary(); RefreshUV2();  GUI.changed = false;
            }

            EditorGUI.showMixedValue = diff["hardAngle"];
            sampleHardAngle          = EditorGUILayout.Slider("Hard Angle", sampleHardAngle, 0f, 180f);
            if (GUI.changed)
            {
                SetHardAngle(sampleHardAngle);  UpdateDiffDictionary(); RefreshUV2();  GUI.changed = false;
            }

            EditorGUI.showMixedValue = diff["packMargin"];
            samplePackMargin         = EditorGUILayout.Slider("Pack Margin", samplePackMargin, 1f, 64f);
            if (GUI.changed)
            {
                SetPackMargin(samplePackMargin);  UpdateDiffDictionary(); RefreshUV2();  GUI.changed = false;
            }

            EditorGUI.showMixedValue = false;

            if (GUILayout.Button("Reset Values to Default"))
            {
                foreach (pb_Object pb in editor.selection)
                {
                    ResetObjectToDefaultValues(pb);
                }

                RefreshUV2();
            }

            showAdvancedPanel = EditorGUILayout.Foldout(showAdvancedPanel, "Advanced");

            if (showAdvancedPanel)
            {
                SetWindowSize(new Vector2(300f, 290f));
                if (GUILayout.Button(new GUIContent("Refresh All", "UV2 is now automatically generated, but if you are upgrading from a previous version this may be necessary.  Caution: Will be slooow in a big scene.")))
                {
                    pb_Object[] all = (pb_Object[])FindObjectsOfType(typeof(pb_Object));
                    foreach (pb_Object pb in all)
                    {
                        pb.GenerateUV2();
                    }
                }

                if (GUILayout.Button(new GUIContent("Apply Settings To All", "Caution: Will be slow in a big scene.")))
                {
                    pb_Object[] all = (pb_Object[])FindObjectsOfType(typeof(pb_Object));
                    foreach (pb_Object pb in all)
                    {
                        pb.angleError = sampleAngleError;
                        pb.areaError  = sampleAreaError;
                        pb.hardAngle  = sampleHardAngle;
                        pb.packMargin = samplePackMargin;
                        pb.GenerateUV2();
                        EditorUtility.SetDirty(pb);
                    }
                }

                if (GUILayout.Button(new GUIContent("Make Current Settings Default", "Sets the default ProBuilder UnwrapParams to the currently set values.")))
                {
                    EditorPrefs.SetFloat("pbAngleError", sampleAngleError);
                    EditorPrefs.SetFloat("pbAreaError", sampleAreaError);
                    EditorPrefs.SetFloat("pbHardAngle", sampleHardAngle);
                    EditorPrefs.SetFloat("pbPackMargin", samplePackMargin);
                }

                if (GUILayout.Button(new GUIContent("Reset Settings to ProBuilder Default", "Sets the default UnwrapParams to the ProBuilder standard.")))
                {
                    ResetProBuilderDefaults();
                }
            }
            else
            {
                SetWindowSize(new Vector2(300f, 210f));
            }

            // if(GUILayout.Button("Generate UV2 Channel"))
            //  GenerateEditorLightmaps();
        }
예제 #14
0
        static Initializer()
        {
            EditorSceneManager.activeSceneChangedInEditMode += OnChangedScene;
            EditorApplication.playModeStateChanged          += OnPlayModeStateChanged;

            bool update = false;

            //find the .gitignore file by searching upwards 3 times
            string ignoreFilePath = FindIgnoreFile();

            if (ignoreFilePath != null)
            {
                //add the References file to the ignore file
                List <string> ignoreLines = File.ReadAllLines(ignoreFilePath).ToList();

                //add the entry
                string comment = "# Referencer asset file";
                string entry   = "*References.asset*";
                if (!ignoreLines.Contains(entry))
                {
                    //check the comment
                    if (!ignoreLines.Contains(comment))
                    {
                        ignoreLines.Add(comment);
                    }
                    else
                    {
                    }

                    ignoreLines.Add(entry);
                    update = true;
                    Debug.Log("[Referencer] A .gitignore file was found. Added a new entry for the Referencer asset file.");
                    File.WriteAllLines(ignoreFilePath, ignoreLines.ToArray());
                }
            }

            string key = Settings.UniqueIdentifier + ".TimeSinceStartup";
            float  lastTimeSinceStartup = EditorPrefs.GetFloat(key);

            EditorPrefs.SetFloat(key, (float)EditorApplication.timeSinceStartup);

            //if the last time is less than the current time, then it was just a recompile
            //otherwise, it was a startup
            if (lastTimeSinceStartup > EditorApplication.timeSinceStartup)
            {
                update = true;
                ResetInitializedScenes();
            }

            //check against license file time
            if (!update)
            {
                string local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string path  = Path.Combine(local, "Unity", "Editor", "Editor.log");

                if (!File.Exists(path))
                {
                    //if editor log doesnt exist, then update
                    update = true;
                    ResetInitializedScenes();
                }
                else
                {
                    DateTime now  = DateTime.Now;
                    DateTime then = GetLicenseTime();

                    key = $"{Settings.UniqueIdentifier}.InitializedLogTime";
                    if (EditorPrefs.GetString(key) == then.ToLongDateString())
                    {
                        return;
                    }

                    //load on boot, 30 seconds should be enough
                    //longer boot times might happen because of first time importing
                    if ((now - then).TotalSeconds < 30)
                    {
                        EditorPrefs.SetString(key, then.ToLongDateString());
                        update = true;
                        ResetInitializedScenes();
                    }
                }
            }

            if (!update)
            {
                //refresh if the references file is empty or doesnt exist
                List <References> references = Loader.FindAssetsByType <References>();
                if (references.Count == 0)
                {
                    update = true;
                    ResetInitializedScenes();
                }
            }

            if (update)
            {
                Helper.LoadAll();
            }
        }
예제 #15
0
 void SetPrefsVector(string key, Vector3 value)
 {
     EditorPrefs.SetFloat(string.Format("{0}.x", key), value.x);
     EditorPrefs.SetFloat(string.Format("{0}.y", key), value.y);
     EditorPrefs.SetFloat(string.Format("{0}.z", key), value.z);
 }
예제 #16
0
 private void SaveSetting()
 {
     EditorPrefs.SetFloat("Unity.TerrainTools.Twist.TwistAmount", m_TwistAmount);
     EditorPrefs.SetBool("Unity.TerrainTools.Twist.Heightmap", m_AffectHeight);
     EditorPrefs.SetBool("Unity.TerrainTools.Twist.Materials", m_AffectMaterials);
 }
예제 #17
0
 public void SetSnapValue(float snapV)
 {
     snapValue = snapV;
     EditorPrefs.SetFloat("polydraw_snapValue", snapValue);
 }
예제 #18
0
 private void SaveSetting()
 {
     EditorPrefs.SetFloat("Unity.TerrainTools.SmoothHeight.Verticality", m_direction);
 }
예제 #19
0
 public static void Reset()
 {
     time = 0;
     EditorPrefs.SetFloat("GrapherTime", 0);
 }
        public void OnGUI()
        {
            // Make sure content color is sane.
            GUI.contentColor = Color.white;

            // Load editor settings.
            timeWindow_exp         = EditorPrefs.GetFloat(TIME_WINDOW_EXP, 0.69897000433f);
            interpolationTypeIndex = EditorPrefs.GetInt(INTERPOLATION_TYPE_INDEX, 0);
            monitorHeight          = EditorPrefs.GetInt(MONITOR_HEIGHT, 140);
            legendWidth            = EditorPrefs.GetInt(LEGEND_WIDTH, 170);

            // Dynamic colors.
            if (EditorGUIUtility.isProSkin)
            {
                legendBackgroundColor         = legendBackgroundColor_dark;
                timeColor                     = timeColor_dark;
                legendTextColorSelected       = legendTextColorSelected_dark;
                legendTextColorUnselected     = legendTextColorUnselected_dark;
                settingsHeaderBackgroundColor = settingsHeaderBackgroundColor_dark;
                monitorInputHeaderColor       = monitorInputHeaderColor_dark;
            }
            else
            {
                legendBackgroundColor         = legendBackgroundColor_light;
                timeColor                     = timeColor_light;
                legendTextColorSelected       = legendTextColorSelected_light;
                legendTextColorUnselected     = legendTextColorUnselected_light;
                settingsHeaderBackgroundColor = settingsHeaderBackgroundColor_light;
                monitorInputHeaderColor       = monitorInputHeaderColor_light;
            }

            timeStyle.normal.textColor = timeColor;

            // textures (must check this in every OnGUI for some reason).

            if (topTexture == null)
            {
                topTexture           = new Texture2D(1, 2);
                topTexture.hideFlags = HideFlags.HideAndDontSave;
                topTexture.wrapMode  = TextureWrapMode.Clamp;
                topTexture.SetPixel(0, 1, new Color(22f / 255f, 22f / 255f, 22f / 255f, 1f));
                topTexture.SetPixel(0, 0, new Color(32f / 255f, 32f / 255f, 32f / 255f, 0f));
                topTexture.Apply();
            }

            if (leftTexture == null)
            {
                leftTexture           = new Texture2D(2, 1);
                leftTexture.hideFlags = HideFlags.HideAndDontSave;
                leftTexture.wrapMode  = TextureWrapMode.Clamp;
                leftTexture.SetPixel(0, 0, new Color(22f / 255f, 22f / 255f, 22f / 255f, 1f));
                leftTexture.SetPixel(1, 0, new Color(32f / 255f, 32f / 255f, 32f / 255f, 0f));
                leftTexture.Apply();
            }

            // calculate dynamic sizes.
            width        = position.width;
            height       = position.height;
            monitorWidth = width - legendWidth - 5f;

            monitorGraphHeight = monitorHeight - headerHeight - extraSpace;

            // settings header (prelude)
            Rect  settingsRect = new Rect(0f, 0f, position.width, 25f);
            float timeWindow   = Mathf.Pow(10f, timeWindow_exp);

            // draw background.
            GUI.color = backgroundColor;
            GUI.DrawTexture(new Rect(0, settingsRect.height, width, height - settingsRect.height), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);

            GUI.color = legendBackgroundColor;
            GUI.DrawTexture(new Rect(0f, settingsRect.height, legendWidth, height - settingsRect.height), EditorGUIUtility.whiteTexture);

            Event e = Event.current;

            Vector2 mousePosition = e.mousePosition;

            mousePosition.x = Mathf.Min(mousePosition.x, width);

            bool isInPauseMode = (EditorApplication.isPlaying && EditorApplication.isPaused);

            if (!isInPauseMode)
            {
                // smooth catch up. Nice!
                scrollPositionTime = 0f;
            }

            if (e.type == EventType.MouseDown &&
                mousePosition.x > legendWidth &&
                (mousePosition.x < (width - 14f)) &&
                mousePosition.y > settingsRect.height)
            {
                Debug.Break();
            }

            MonitorInput newSelectedMonitorInput = null;

            int lineCount = 0;

            List <Monitor> visibleMonitors;

            if (gameObjectFilter != null)
            {
                visibleMonitors = new List <Monitor>();                // TODO: remove alloc.
                foreach (var monitor in monitors.All)
                {
                    if (monitor.GameObject == gameObjectFilter)
                    {
                        visibleMonitors.Add(monitor);
                    }
                }
            }
            else
            {
                visibleMonitors = monitors.All;
            }

            float latestTime = 0f;

            for (int i = 0; i < visibleMonitors.Count; i++)
            {
                latestTime = Mathf.Max(latestTime, visibleMonitors[i].latestTime);
            }

            for (int i = 0; i < visibleMonitors.Count; i++)
            {
                Monitor monitor = visibleMonitors[i];

                Rect monitorRect = new Rect(legendWidth, i * monitorHeight + settingsRect.height - scrollPositionY, monitorWidth, monitorHeight);
                Rect graphRect   = new Rect(monitorRect.xMin, monitorRect.yMin + headerHeight, monitorRect.width - 20, monitorGraphHeight - 5);

                float span = monitor.Max - monitor.Min;

                GUI.color = Color.white;
                GUI.Label(new Rect(legendWidth + 10f, monitorRect.yMin + 10, 100f, 30f), monitor.Name, headerStyle);

                float maxTime = latestTime + scrollPositionTime;
                float minTime = latestTime - timeWindow + scrollPositionTime;

                if (monitor.Mode == ValueAxisMode.Adaptive)
                {
                    monitor.Min = float.PositiveInfinity;
                    monitor.Max = float.NegativeInfinity;

                    foreach (MonitorInput monitorInput in monitor.inputs)
                    {
                        float min, max;
                        monitorInput.GetMinMax(minTime, maxTime, out min, out max);
                        monitor.Min = Mathf.Min(min, monitor.Min);
                        monitor.Max = Mathf.Max(max, monitor.Max);
                    }
                }

                if (monitor.Min < float.PositiveInfinity)
                {
                    GUI.Label(new Rect(graphRect.xMax - 200f - 5f, graphRect.yMax + 5f, 200f, 20f), monitor.Min.ToString(), minStyle);
                }

                if (monitor.Max > float.NegativeInfinity)
                {
                    GUI.Label(new Rect(graphRect.xMax - 200f - 5f, graphRect.yMin - 5f - 20f, 200f, 20f), monitor.Max.ToString(), maxStyle);
                }

                // monitor resizing.

                Rect resizeRect = new Rect(0f, monitorRect.yMax - 10, width - 12, 21);
                if (!legendResize)
                {
                    EditorGUIUtility.AddCursorRect(resizeRect, MouseCursor.SplitResizeUpDown);
                }

                if (e.type == EventType.MouseDown && resizeRect.Contains(mousePosition) && !legendResize)
                {
                    monitorHeightResize          = true;
                    monitorHeightResizeIndex     = i;
                    monitorHeightResizeOldHeight = monitorHeight;
                    monitorHeightResizeYstart    = mousePosition.y;
                    monitorHeightResizeDelta     = 0;
                }

                if (e.type == EventType.MouseDrag && monitorHeightResize)
                {
                    monitorHeightResizeDelta = (mousePosition.y - monitorHeightResizeYstart);
                    monitorHeight            = monitorHeightResizeOldHeight + Mathf.FloorToInt(monitorHeightResizeDelta / (monitorHeightResizeIndex + 1));

                    if (monitorHeight < monitorHeight_min)
                    {
                        monitorHeight = monitorHeight_min;
                    }

                    if (monitorHeight > monitorHeight_max)
                    {
                        monitorHeight = monitorHeight_max;
                    }
                }

                if (e.type == EventType.MouseUp && monitorHeightResize)
                {
                    monitorHeightResize = false;
                }

                // Is monitor visible? otherwise cull...
                if (monitorRect.yMin < position.height && monitorRect.yMax > 0f)
                {
                    Handles.color = zeroLineColor;

                    horizontalLines[0] = new Vector3(graphRect.xMax, graphRect.yMin);
                    horizontalLines[1] = new Vector3(graphRect.xMin, graphRect.yMin);
                    horizontalLines[2] = new Vector3(graphRect.xMin, Mathf.Clamp(graphRect.height * monitor.Min / span + graphRect.yMax, graphRect.yMin, graphRect.yMax));

                    if (monitor.Min <= 0f && monitor.Max >= 0f)
                    {
                        horizontalLines[3] = new Vector3(graphRect.xMax, Mathf.Clamp(graphRect.height * monitor.Min / span + graphRect.yMax, graphRect.yMin, graphRect.yMax));
                    }
                    else
                    {
                        horizontalLines[3] = new Vector3(graphRect.xMin, Mathf.Clamp(graphRect.height * monitor.Min / span + graphRect.yMax, graphRect.yMin, graphRect.yMax));
                    }

                    horizontalLines[4] = new Vector3(graphRect.xMin, Mathf.Clamp(graphRect.height * monitor.Min / span + graphRect.yMax, graphRect.yMin, graphRect.yMax));
                    horizontalLines[5] = new Vector3(graphRect.xMin, graphRect.yMax);
                    horizontalLines[6] = new Vector3(graphRect.xMax, graphRect.yMax);

                    Handles.DrawPolyLine(horizontalLines);

                    lineCount++;

                    if (isInPauseMode)
                    {
                        float time = (maxTime - minTime) * (mousePosition.x - graphRect.xMin) / graphRect.width + minTime;

                        if (graphRect.Contains(mousePosition))
                        {
                            if (e.type == EventType.MouseDown)
                            {
                                timeIntervalStartTime        = Mathf.Max(0f, time);
                                timeIntervalEndTime          = timeIntervalStartTime;
                                timeIntervalSelectionMonitor = monitor;
                            }
                        }

                        if (timeIntervalSelectionMonitor == monitor && e.type == EventType.MouseDrag)
                        {
                            timeIntervalEndTime = Mathf.Max(0f, time);
                        }
                    }

                    int   n         = 0;
                    float startTime = Mathf.CeilToInt(minTime / subTimeTicks) * subTimeTicks;
                    float t         = startTime;

                    float transparentTime = 3;
                    float opaqueTime      = 2;

                    // Sub tick lines.
                    if (timeWindow < transparentTime)
                    {
                        Color subTimeTickColorWithAlpha = subTimeTickColor;
                        subTimeTickColorWithAlpha.a = subTimeTickColor.a * Mathf.Lerp(1f, 0f, (timeWindow - opaqueTime) / (transparentTime - opaqueTime));

                        Handles.color = subTimeTickColorWithAlpha;

                        while (t < maxTime)
                        {
                            Handles.DrawLine(
                                new Vector3(graphRect.xMin + graphRect.width * (t - minTime) / timeWindow, graphRect.yMax, 0f),
                                new Vector3(graphRect.xMin + graphRect.width * (t - minTime) / timeWindow, graphRect.yMax - graphRect.height, 0f)
                                );

                            lineCount++;

                            n++;
                            t = startTime + n * 0.1f;
                        }
                    }


                    // Tick lines.
                    Handles.color = timeTickColor;
                    n             = 0;
                    startTime     = Mathf.CeilToInt(minTime);
                    t             = startTime;

                    while (t < maxTime)
                    {
                        Handles.DrawLine(
                            new Vector3(graphRect.xMin + graphRect.width * (t - minTime) / timeWindow, graphRect.yMax, 0f),
                            new Vector3(graphRect.xMin + graphRect.width * (t - minTime) / timeWindow, graphRect.yMax - graphRect.height, 0f)
                            );

                        lineCount++;

                        n++;
                        t = startTime + n;
                    }

                    foreach (MonitorInput monitorInput in monitor.inputs)
                    {
                        Color deselectedColor = monitorInput.Color;
                        deselectedColor.a = deselectionAlpha;

                        Color color = (selectedMonitorInput == null) || (monitorInput == selectedMonitorInput) ? monitorInput.Color : deselectedColor;

                        Handles.color = color;

                        int pointIndex = 0;

                        for (int j = 0; j < monitorInput.numberOfSamples - 1; j++)
                        {
                            int index_a = (monitorInput.sampleIndex + j) % monitorInput.numberOfSamples;
                            int index_b = (index_a + 1) % monitorInput.numberOfSamples;

                            float time_a = monitorInput.times[index_a];
                            float time_b = monitorInput.times[index_b];

                            if (float.IsNaN(time_a) || float.IsNaN(time_b))
                            {
                                continue;
                            }

                            if (time_b > time_a && !(time_b < minTime || time_a > maxTime))
                            {
                                float sample_a = monitorInput.samples[index_a];
                                float sample_b = monitorInput.samples[index_b];

                                if (float.IsNaN(sample_a) || float.IsNaN(sample_b))
                                {
                                    continue;
                                }

                                float aNormalizedSample = (sample_a - monitor.Min) / span;
                                if (span == 0f)
                                {
                                    aNormalizedSample = 0.5f;
                                }
                                else
                                {
                                    aNormalizedSample = Mathf.Clamp01(aNormalizedSample);
                                }

                                float bNormalizedSample = (sample_b - monitor.Min) / span;
                                if (span == 0f)
                                {
                                    bNormalizedSample = 0.5f;
                                }
                                else
                                {
                                    bNormalizedSample = Mathf.Clamp01(bNormalizedSample);
                                }

                                // Draw graph step.
                                if (interpolationTypeIndex == 0)
                                {
                                    points[pointIndex++] = new Vector3(graphRect.xMin + graphRect.width * (time_b - minTime) / timeWindow, graphRect.yMin + graphRect.height * (1f - bNormalizedSample), 0f);
                                }
                                else
                                {
                                    points[pointIndex++] = new Vector3(graphRect.xMin + graphRect.width * (time_b - minTime) / timeWindow, graphRect.yMin + graphRect.height * (1f - aNormalizedSample), 0f);
                                    points[pointIndex++] = new Vector3(graphRect.xMin + graphRect.width * (time_b - minTime) / timeWindow, graphRect.yMin + graphRect.height * (1f - bNormalizedSample), 0f);
                                }
                            }
                        }

                        if (pointIndex > 0)
                        {
                            Vector3 lastPoint = points[pointIndex - 1];

                            for (int p = pointIndex; p < points.Length; p++)
                            {
                                points[p] = lastPoint;
                            }

                            Handles.DrawPolyLine(points);
                            lineCount++;
                        }
                    }

                    if (timeIntervalSelectionMonitor == monitor && timeIntervalStartTime != timeIntervalEndTime)
                    {
                        GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.1f);

                        float selectionTime_left  = Mathf.Max(0f, Mathf.Min(timeIntervalStartTime, timeIntervalEndTime));
                        float selectionTime_right = Mathf.Max(0f, Mathf.Max(timeIntervalStartTime, timeIntervalEndTime));

                        float left  = graphRect.width * (selectionTime_left - minTime) / (maxTime - minTime) + graphRect.xMin;
                        float right = graphRect.width * (selectionTime_right - minTime) / (maxTime - minTime) + graphRect.xMin;

                        GUI.DrawTexture(new Rect(left, graphRect.yMin, right - left, graphRect.height), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);

                        Handles.color = new Color(1f, 1f, 1f, 0.3f);
                        Handles.DrawLine(new Vector3(left, 0, 0), new Vector3(left, height, 0));
                        Handles.DrawLine(new Vector3(right, 0, 0), new Vector3(right, height, 0));

                        GUI.color     = Color.white;
                        Handles.color = Color.white;
                        Handles.DrawLine(new Vector3(left, graphRect.yMin, 0), new Vector3(left, graphRect.yMax, 0));
                        Handles.DrawLine(new Vector3(right, graphRect.yMin, 0), new Vector3(right, graphRect.yMax, 0));
                        Handles.DrawLine(new Vector3(left, (graphRect.yMin + graphRect.yMax) * 0.5f, 0), new Vector3(right, (graphRect.yMin + graphRect.yMax) * 0.5f, 0));

                        GUI.Label(new Rect(left, graphRect.yMax, right - left, 20), (selectionTime_right - selectionTime_left) + " secs", timeIntervalSelectionStyle);
                    }


                    GUI.color = legendBackgroundColor;
                    GUI.DrawTexture(new Rect(0f, monitorRect.yMin, legendWidth, monitorRect.height + 5), EditorGUIUtility.whiteTexture);

                    // Game object name label.

                    if (monitor.GameObject != null)
                    {
                        Rect gameObjectNameRect = new Rect(22f, monitorRect.yMin + 10f, legendWidth - 30f, 16f);

                        GUI.color = monitorInputHeaderColor;
                        GUI.Label(gameObjectNameRect, monitor.GameObject.name, simpleStyle);

                        EditorGUIUtility.AddCursorRect(gameObjectNameRect, MouseCursor.Link);

                        if (e.type == EventType.MouseDown && gameObjectNameRect.Contains(mousePosition))
                        {
                            EditorGUIUtility.PingObject(monitor.GameObject);
                        }
                    }

                    // Time line.

                    float mouseTime = maxTime;

                    if (isInPauseMode)
                    {
                        mouseTime = Mathf.Lerp(minTime, maxTime, (mousePosition.x - graphRect.xMin) / graphRect.width);
                    }

                    mouseTime = Mathf.Max(mouseTime, 0f);

                    Handles.color = timeLineColor;
                    float x = (mouseTime - minTime) / (maxTime - minTime) * graphRect.width + graphRect.xMin;
                    Handles.DrawLine(new Vector3(x, settingsRect.height), new Vector3(x, position.height));

                    for (int j = 0; j < monitor.inputs.Count; j++)
                    {
                        MonitorInput monitorInput = monitor.inputs[j];

                        Color deselectedColor = monitorInput.Color;
                        deselectedColor.a = deselectionAlpha;

                        Color monitorInputColor = (selectedMonitorInput == null) || (monitorInput == selectedMonitorInput) ? monitorInput.Color : deselectedColor;

                        int index = -1;

                        for (int k = 1; k < monitorInput.samples.Length - 1; k++)
                        {
                            int sampleIndex_a = (monitorInput.sampleIndex + k) % monitorInput.samples.Length;
                            int sampleIndex_b = (sampleIndex_a + 1) % monitorInput.samples.Length;

                            if (mouseTime >= monitorInput.times[sampleIndex_a] &&
                                mouseTime <= monitorInput.times[sampleIndex_b])
                            {
                                index = Mathf.Abs(monitorInput.times[sampleIndex_a] - mouseTime) <= Mathf.Abs(monitorInput.times[sampleIndex_b] - mouseTime) ? sampleIndex_a : sampleIndex_b;
                                break;
                            }
                        }

                        float sampleValue = float.NaN;
                        float time        = float.NaN;
                        int   frame       = -1;

                        if (index > -1)
                        {
                            sampleValue = monitorInput.samples[index];
                            time        = monitorInput.times[index];
                            frame       = monitorInput.frames[index];
                        }

                        // Draw time marker.
                        if (j == 0 && selectedMonitorInput == null)
                        {
                            GUI.color = timeColor;

                            if (!float.IsNaN(time))
                            {
                                GUI.Label(new Rect(legendTextOffset, monitorRect.yMax - legendTextOffset * 2f, legendWidth, 20),
                                          "t = " + time, timeStyle);
                            }

                            if (frame > -1)
                            {
                                GUI.Label(new Rect(legendTextOffset, monitorRect.yMax - legendTextOffset * 3.5f, legendWidth, 20),
                                          "frame = " + frame, timeStyle);
                            }
                        }

                        Handles.color = monitorInputColor;

                        float normalizedSampleValue = (sampleValue - monitor.Min) / span;
                        if (span == 0f)
                        {
                            normalizedSampleValue = 0.5f;
                        }

                        float clampedNormalizedSampleValue = Mathf.Clamp01(normalizedSampleValue);

                        Vector3 samplePosition = new Vector3(graphRect.xMin + graphRect.width * (time - minTime) / timeWindow, graphRect.yMax - graphRect.height * clampedNormalizedSampleValue, 0f);

                        float handleRadius = 5f;

                        if (normalizedSampleValue < 0f)
                        {
                            // Draw down arrow.
                            arrowPoints[0] = samplePosition + new Vector3(-handleRadius, -handleRadius, 0);
                            arrowPoints[1] = samplePosition + new Vector3(handleRadius, -handleRadius, 0);
                            arrowPoints[2] = samplePosition + new Vector3(0, handleRadius, 0);
                            arrowPoints[3] = arrowPoints[0];

                            Handles.DrawPolyLine(arrowPoints);
                            lineCount++;
                        }
                        else if (normalizedSampleValue > 1f)
                        {
                            // Draw up arrow.
                            arrowPoints[0] = samplePosition + new Vector3(-handleRadius, handleRadius, 0);
                            arrowPoints[1] = samplePosition + new Vector3(handleRadius, handleRadius, 0);
                            arrowPoints[2] = samplePosition + new Vector3(0, -handleRadius, 0);
                            arrowPoints[3] = arrowPoints[0];

                            Handles.DrawPolyLine(arrowPoints);
                            lineCount++;
                        }
                        else
                        {
                            // Draw circle.
                            float size = handleRadius * 0.75f;
                            diamondPoints[0] = samplePosition + new Vector3(0, size, 0);
                            diamondPoints[1] = samplePosition + new Vector3(size, 0, 0);
                            diamondPoints[2] = samplePosition + new Vector3(0, -size, 0);
                            diamondPoints[3] = samplePosition + new Vector3(-size, 0, 0);
                            diamondPoints[4] = diamondPoints[0];

                            Handles.DrawPolyLine(diamondPoints);
                            lineCount++;
                        }

                        string sampleValueString;
                        if (float.IsNaN(sampleValue))
                        {
                            sampleValueString = "";
                        }
                        else
                        {
                            sampleValueString = " = " + sampleValue.ToString();
                        }

                        string valueText = monitorInput.Description + sampleValueString;

                        GUI.color = new Color(1f, 1f, 1f, 1f);
                        valueTextStyle.normal.textColor = Color.white;

                        if (monitorInput == selectedMonitorInput)
                        {
                            float sampleTextWidth = valueTextStyle.CalcSize(new GUIContent(valueText)).x;

                            if (samplePosition.x + sampleTextWidth + 40 > position.width)
                            {
                                valueTextStyle.alignment = TextAnchor.MiddleRight;
                                GUI.Label(new Rect(samplePosition.x - sampleTextWidth - 15, samplePosition.y - 20, sampleTextWidth, 20), valueText, valueTextStyle);
                            }
                            else
                            {
                                valueTextStyle.alignment = TextAnchor.MiddleLeft;
                                GUI.Label(new Rect(samplePosition.x + 15, samplePosition.y, sampleTextWidth, 20), valueText, valueTextStyle);
                            }

                            GUI.color = new Color(1f, 1f, 1f, 0.5f);
                            GUI.Label(new Rect(10, graphRect.yMax - 10, legendWidth, 20), "Time = " + time, timeStyle);
                        }

                        GUI.color = new Color(1f, 1f, 1f, 1f);

                        valueTextStyle.normal.textColor = selectedMonitorInput == null || selectedMonitorInput == monitorInput ? legendTextColorSelected : legendTextColorUnselected;
                        valueTextStyle.alignment        = TextAnchor.MiddleLeft;
                        valueTextStyle.clipping         = TextClipping.Clip;

                        float offset        = 30f;
                        Rect  selectionRect = new Rect(0f, monitorRect.yMin + offset + 20 * j, legendWidth, 16f);
                        GUI.Label(new Rect(22f, monitorRect.yMin + 30f + 20 * j, legendWidth - 30f, 16f), valueText, valueTextStyle);

                        EditorGUIUtility.AddCursorRect(selectionRect, MouseCursor.Link);

                        // Selection of monitor input.
                        if (e.type == EventType.MouseDown && selectionRect.Contains(mousePosition))
                        {
                            newSelectedMonitorInput = monitorInput;
                        }

                        // Color marker.
                        GUI.color = monitorInputColor * 0.7f;
                        GUI.DrawTexture(new Rect(10, monitorRect.yMin + offset + 20 * j + 6, 7, 7), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);

                        GUI.color = monitorInputColor;
                        GUI.DrawTexture(new Rect(10 + 1, monitorRect.yMin + offset + 20 * j + 7, 5, 5), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);

                        GUI.color = new Color(1f, 1f, 1f, 1f);
                    }

                    List <MonitorEvent> monitorEvents = new List <MonitorEvent>();
                    monitor.GetEvents(maxTime - timeWindow, maxTime, monitorEvents);

                    foreach (var monitorEvent in monitorEvents)
                    {
                        Color eventColor = Color.yellow;
                        Handles.color = eventColor;

                        float normalizedX = (monitorEvent.time - minTime) / timeWindow;
                        if (normalizedX * graphRect.width >= 5f)
                        {
                            Handles.DrawLine(
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX, graphRect.yMin, 0f),
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX, graphRect.yMax, 0f)
                                );
                            lineCount++;

                            Handles.DrawLine(
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX, graphRect.yMax, 0f),
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX + 5, graphRect.yMax + 5, 0f)
                                );
                            lineCount++;

                            Handles.DrawLine(
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX, graphRect.yMax, 0f),
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX - 5, graphRect.yMax + 5, 0f)
                                );
                            lineCount++;

                            Handles.DrawLine(
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX - 5, graphRect.yMax + 5, 0f),
                                new Vector3(graphRect.xMin + graphRect.width * normalizedX + 5, graphRect.yMax + 5, 0f)
                                );
                            lineCount++;

                            GUI.color        = eventColor;
                            GUI.contentColor = Color.white;
                            GUI.Label(new Rect(graphRect.xMin + graphRect.width * normalizedX - 5, graphRect.yMax + 5f, 100f, 20f), monitorEvent.text, simpleStyle);
                        }
                    }
                }
            }

            // select/deselect.
            if (e.type == EventType.MouseDown)
            {
                selectedMonitorInput = newSelectedMonitorInput;
            }

            // Left gradient.
            GUI.DrawTexture(new Rect(legendWidth, settingsRect.height, 10f, position.height - settingsRect.height), leftTexture, ScaleMode.StretchToFill, true);

            // Draw top gradient.
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.DrawTexture(new Rect(0, settingsRect.height, width, 8), topTexture, ScaleMode.StretchToFill);

            for (int i = 0; i < visibleMonitors.Count; i++)
            {
                // separator line
                Handles.color = Color.grey;
                Handles.DrawLine(new Vector3(0f, (i + 1) * monitorHeight + settingsRect.height - scrollPositionY, 0f),
                                 new Vector3(width, (i + 1) * monitorHeight + settingsRect.height - scrollPositionY, 0f));
                lineCount++;
            }

            // Scrollbar
            float scrollMaxY     = monitorHeight * visibleMonitors.Count + extraScrollSpace;
            float visibleHeightY = Mathf.Min(scrollMaxY, position.height - settingsRect.height);

            GUI.color       = Color.white;
            scrollPositionY = GUI.VerticalScrollbar(new Rect(
                                                        position.width - 15, settingsRect.height, 15f, position.height - settingsRect.height),
                                                    scrollPositionY, visibleHeightY, 0f, scrollMaxY);
            scrollPositionY = Mathf.Max(scrollPositionY, 0f);

            if (isInPauseMode)
            {
                if (!wasInPauseMode)
                {
                    // Reset scroll positionwhen going into pause mode.
                    scrollPositionTime = 0f;

                    // Find the maximum time span in samples.

                    float minTime = float.PositiveInfinity;
                    float maxTime = float.NegativeInfinity;

                    foreach (var monitor in visibleMonitors)
                    {
                        float monitorMinTime, monitorMaxTime;
                        monitor.GetMinMaxTime(out monitorMinTime, out monitorMaxTime);

                        minTime = Mathf.Min(minTime, monitorMinTime);
                        maxTime = Mathf.Max(maxTime, latestTime);
                    }

                    scrollPositionTimeMax = (maxTime - minTime) + 1f;
                }

                GUI.color          = Color.white;
                scrollPositionTime = GUI.HorizontalScrollbar(
                    new Rect(legendWidth, height - 15f, width - legendWidth - 15f, 15f),
                    scrollPositionTime,
                    Mathf.Min(scrollPositionTimeMax, timeWindow),
                    -scrollPositionTimeMax + timeWindow,
                    timeWindow
                    );

                scrollPositionTime = Mathf.Min(0f, scrollPositionTime);
            }

            // Top settings
            GUI.color = settingsHeaderBackgroundColor;
            GUI.DrawTexture(settingsRect, EditorGUIUtility.whiteTexture);
            GUI.color = Color.white;

            float padding           = 5f;
            float timeWindowFloored = Mathf.RoundToInt(timeWindow * 10f) / 10f;

            GUILayout.BeginArea(new Rect(settingsRect.xMin + padding, settingsRect.yMin + padding, settingsRect.width - 2 * padding, settingsRect.height - 2 * padding));
            GUILayout.BeginHorizontal();

            // Find list of unique game objects (linked to monitors).
            List <GameObject> gameObjects = new List <GameObject>();

            foreach (Monitor monitor in monitors.All)
            {
                if (monitor.GameObject != null)
                {
                    if (!gameObjects.Contains(monitor.GameObject))
                    {
                        gameObjects.Add(monitor.GameObject);
                    }
                }
            }

            gameObjects.Sort((GameObject a, GameObject b) => {
                int nameDelta = a.name.CompareTo(b.name);
                if (nameDelta == 0)
                {
                    return(a.GetInstanceID().CompareTo(b.GetInstanceID()));
                }
                else
                {
                    return(nameDelta);
                }
            });

            string[] visibleGameObjectNames = new string[gameObjects.Count];
            for (int i = 0; i < visibleGameObjectNames.Length; i++)
            {
                visibleGameObjectNames[i] = gameObjects[i].name;
            }

            for (int i = 0; i < visibleGameObjectNames.Length; i++)
            {
                int lastIndexWithSameName = i;
                for (int j = i + 1; j < visibleGameObjectNames.Length; j++)
                {
                    if (visibleGameObjectNames[j] == visibleGameObjectNames[i])
                    {
                        lastIndexWithSameName = j;
                    }
                    else
                    {
                        break;
                    }
                }

                if (lastIndexWithSameName > i)
                {
                    int n = 1;
                    for (int j = i; j <= lastIndexWithSameName; j++)
                    {
                        visibleGameObjectNames[j] = visibleGameObjectNames[j] + "/" + n + "";
                        n++;
                    }

                    i = lastIndexWithSameName + 1;
                }
            }

            // Game object filter.

            int gameObjectFilterIndex = 0;

            string[] gameObjectFilterOptions = new string[gameObjects.Count + 1];
            gameObjectFilterOptions[0] = "All";
            for (int i = 0; i < gameObjects.Count; i++)
            {
                gameObjectFilterOptions[i + 1] = visibleGameObjectNames[i];

                if (gameObjectFilter == gameObjects[i])
                {
                    gameObjectFilterIndex = i + 1;
                }
            }

            gameObjectFilterIndex = EditorGUILayout.Popup(gameObjectFilterIndex, gameObjectFilterOptions, GUILayout.Width(160));


            GameObject gameObjectFilter_old = gameObjectFilter;

            if (gameObjectFilterIndex == 0)
            {
                gameObjectFilter = null;
            }
            else
            {
                gameObjectFilter = gameObjects[gameObjectFilterIndex - 1];
            }

            if (gameObjectFilter != gameObjectFilter_old)
            {
                scrollPositionY = 0;
            }

            // Interpolation selection.
            GUILayout.Space(5f);
            GUILayout.Label("Interpolation", GUILayout.Width(75));
            interpolationTypeIndex = EditorGUILayout.Popup(interpolationTypeIndex, interpolationTypes, GUILayout.Width(120));

            timeWindow_exp = GUILayout.HorizontalSlider(timeWindow_exp, -1f, 1.30102999566f);
            GUILayout.Label(timeWindowFloored.ToString("0.0") + " secs.", GUILayout.Width(60));
            GUILayout.Space(5f);

            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            float splitSize        = 6;
            Rect  legendResizeRect = new Rect(legendWidth - splitSize / 2, 0, splitSize, height);

            EditorGUIUtility.AddCursorRect(legendResizeRect, MouseCursor.SplitResizeLeftRight);

            if (e.type == EventType.MouseDown && legendResizeRect.Contains(mousePosition) && !monitorHeightResize)
            {
                legendResize = true;
            }

            if (e.type == EventType.MouseDrag && legendResize)
            {
                legendWidth = Mathf.FloorToInt(mousePosition.x);
            }

            if (e.type == EventType.MouseUp && legendResize)
            {
                legendResize = false;
            }

            Repaint();

            wasInPauseMode = isInPauseMode;

            // Save editor settings.
            EditorPrefs.SetFloat(TIME_WINDOW_EXP, timeWindow_exp);
            EditorPrefs.SetInt(INTERPOLATION_TYPE_INDEX, interpolationTypeIndex);
            EditorPrefs.SetInt(MONITOR_HEIGHT, monitorHeight);
            EditorPrefs.SetInt(LEGEND_WIDTH, legendWidth);
        }
예제 #21
0
    private static void SaveSetting(string settingName, float value)
    {
        string prefName = prefsClassName + settingName;

        EditorPrefs.SetFloat(prefName, value);
    }
예제 #22
0
 public void Save(string key)
 {
     EditorPrefs.SetString(key + "_NAME", UnitName);
     EditorPrefs.SetFloat(key + "_VALUE", Value);
     EditorPrefs.SetString(key + "_RELATIVE", RelativeUnit);
 }
예제 #23
0
            public static void HandlePreferencesGUI()
            {
                if (!preferencesLoaded)
                {
                    Load();
                }

                EditorGUI.BeginChangeCheck();
                showHierarchyIcons = EditorGUILayout.Toggle(new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes."), showHierarchyIcons);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, showHierarchyIcons);
#if NEWPLAYMODECALLBACKS
                    HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
#else
                    HierarchyHandler.IconsOnPlaymodeStateChanged();
#endif
                }

                BoolPrefsField(ref autoReloadSceneSkeletons, AUTO_RELOAD_SCENESKELETONS_KEY, new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."));

                EditorGUILayout.Separator();
                EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.FloatPrefsField(ref defaultMix, DEFAULT_MIX_KEY, new GUIContent("Default Mix", "The Default Mix Duration for newly imported SkeletonDataAssets."), min: 0);
                    SpineEditorUtilities.FloatPrefsField(ref defaultScale, DEFAULT_SCALE_KEY, new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);

                    EditorGUI.BeginChangeCheck();
                    var shader = (EditorGUILayout.ObjectField("Default Shader", Shader.Find(defaultShader), typeof(Shader), false) as Shader);
                    defaultShader = shader != null ? shader.name : SpinePreferences.DEFAULT_DEFAULT_SHADER;
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader);
                    }

                    SpineEditorUtilities.BoolPrefsField(ref setTextureImporterSettings, SET_TEXTUREIMPORTER_SETTINGS_KEY, new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."));
                    SpineEditorUtilities.Texture2DPrefsField(ref textureSettingsReference, TEXTURE_SETTINGS_REFERENCE_KEY, new GUIContent("Atlas Texture Reference Settings", "Apply the selected reference texture import settings at newly imported atlas textures. When exporting atlas textures from Spine with \"Premultiply alpha\" enabled (the default), you can leave it at \"PMAPresetTemplate\". If you have disabled \"Premultiply alpha\", set it to \"StraightAlphaPresetTemplate\". You can also create your own reference texture asset and assign it here."));
                    if (string.IsNullOrEmpty(textureSettingsReference))
                    {
                        var pmaTextureSettingsReferenceGUIDS = AssetDatabase.FindAssets("PMAPresetTemplate");
                        if (pmaTextureSettingsReferenceGUIDS.Length > 0)
                        {
                            textureSettingsReference = AssetDatabase.GUIDToAssetPath(pmaTextureSettingsReferenceGUIDS[0]);
                            EditorPrefs.SetString(TEXTURE_SETTINGS_REFERENCE_KEY, textureSettingsReference);
                        }
                    }

                    SpineEditorUtilities.MaterialPrefsField(ref blendModeMaterialAdditive, BLEND_MODE_MATERIAL_ADDITIVE_KEY, new GUIContent("Additive Material", "Additive blend mode Material template."));
                    if (string.IsNullOrEmpty(blendModeMaterialAdditive))
                    {
                        var blendModeMaterialAdditiveGUIDS = AssetDatabase.FindAssets(DEFAULT_BLEND_MODE_ADDITIVE_MATERIAL);
                        if (blendModeMaterialAdditiveGUIDS.Length > 0)
                        {
                            blendModeMaterialAdditive = AssetDatabase.GUIDToAssetPath(blendModeMaterialAdditiveGUIDS[0]);
                        }
                    }
                    SpineEditorUtilities.MaterialPrefsField(ref blendModeMaterialMultiply, BLEND_MODE_MATERIAL_MULTIPLY_KEY, new GUIContent("Multiply Material", "Multiply blend mode Material template."));
                    if (string.IsNullOrEmpty(blendModeMaterialMultiply))
                    {
                        var blendModeMaterialMultiplyGUIDS = AssetDatabase.FindAssets(DEFAULT_BLEND_MODE_MULTIPLY_MATERIAL);
                        if (blendModeMaterialMultiplyGUIDS.Length > 0)
                        {
                            blendModeMaterialMultiply = AssetDatabase.GUIDToAssetPath(blendModeMaterialMultiplyGUIDS[0]);
                        }
                    }
                    SpineEditorUtilities.MaterialPrefsField(ref blendModeMaterialScreen, BLEND_MODE_MATERIAL_SCREEN_KEY, new GUIContent("Screen Material", "Screen blend mode Material template."));
                    if (string.IsNullOrEmpty(blendModeMaterialScreen))
                    {
                        var blendModeMaterialScreenGUIDS = AssetDatabase.FindAssets(DEFAULT_BLEND_MODE_SCREEN_MATERIAL);
                        if (blendModeMaterialScreenGUIDS.Length > 0)
                        {
                            blendModeMaterialScreen = AssetDatabase.GUIDToAssetPath(blendModeMaterialScreenGUIDS[0]);
                        }
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Warnings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref atlasTxtImportWarning, ATLASTXT_WARNING_KEY, new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found."));
                    SpineEditorUtilities.BoolPrefsField(ref textureImporterWarning, TEXTUREIMPORTER_WARNING_KEY, new GUIContent("Texture Settings Warning", "Log a warning and recommendation whenever Texture Import Settings are detected that could lead to undesired effects, e.g. white border artifacts."));
                    SpineEditorUtilities.BoolPrefsField(ref componentMaterialWarning, COMPONENTMATERIAL_WARNING_KEY, new GUIContent("Component & Material Warning", "Log a warning and recommendation whenever Component and Material settings are not compatible."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    defaultZSpacing = EditorGUILayout.Slider("Default Slot Z-Spacing", defaultZSpacing, -0.1f, 0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(DEFAULT_ZSPACING_KEY, defaultZSpacing);
                    }

                    SpineEditorUtilities.BoolPrefsField(ref defaultInstantiateLoop, DEFAULT_INSTANTIATE_LOOP_KEY, new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Mecanim Bake Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref mecanimEventIncludeFolderName, MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, new GUIContent("Include Folder Name in Event", "When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    handleScale = EditorGUILayout.Slider("Editor Bone Scale", handleScale, 0.01f, 2f);
                    handleScale = Mathf.Max(0.01f, handleScale);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(SCENE_ICONS_SCALE_KEY, handleScale);
                        SceneView.RepaintAll();
                    }
                }

#if SPINE_TK2D_DEFINE
                bool isTK2DDefineSet = true;
#else
                bool isTK2DDefineSet = false;
#endif
                bool isTK2DAllowed = SpineTK2DEditorUtility.IsTK2DAllowed;
                if (SpineTK2DEditorUtility.IsTK2DInstalled() || isTK2DDefineSet)
                {
                    GUILayout.Space(20);
                    EditorGUILayout.LabelField("3rd Party Settings", EditorStyles.boldLabel);
                    using (new GUILayout.HorizontalScope()) {
                        EditorGUILayout.PrefixLabel("Define TK2D");
                        if (isTK2DAllowed && GUILayout.Button("Enable", GUILayout.Width(64)))
                        {
                            SpineTK2DEditorUtility.EnableTK2D();
                        }
                        if (GUILayout.Button("Disable", GUILayout.Width(64)))
                        {
                            SpineTK2DEditorUtility.DisableTK2D();
                        }
                    }
#if !SPINE_TK2D_DEFINE
                    if (!isTK2DAllowed)
                    {
                        EditorGUILayout.LabelField("To allow TK2D support, please modify line 67 in", EditorStyles.boldLabel);
                        EditorGUILayout.LabelField("Spine/Editor/spine-unity/Editor/Util./BuildSettings.cs", EditorStyles.boldLabel);
                    }
#endif
                }

                GUILayout.Space(20);
                EditorGUILayout.LabelField("Timeline Extension", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref timelineUseBlendDuration, TIMELINE_USE_BLEND_DURATION_KEY, new GUIContent("Use Blend Duration", "When enabled, MixDuration will be synced with timeline clip transition duration 'Ease In Duration'."));
                }
            }
예제 #24
0
 private static void SetFloat(string name, float value)
 {
     EditorPrefs.SetFloat(string.Format("HierarchyPro.{0}.float", name), value);
 }
예제 #25
0
 void SaveSettings()
 {
     EditorPrefs.SetFloat("Navigation2D_navmeshExtends", navmeshExtends);
     EditorPrefs.SetInt("Navigation2D_drawMode", drawMode);
 }
예제 #26
0
 private void SaveSettings()
 {
     EditorPrefs.SetFloat("PlayMaker.TimelineWindow.TimeScale", this.timelineControl.TimeScale);
     EditorPrefs.SetFloat("PlayMaker.TimelineWindow.Offset", this.timelineControl.Offset);
     EditorPrefs.SetInt("PlayMaker.TimelineWindow.FilterMode", (int)this.filterMode);
 }
        public void SetValue(System.Type className, string instanceName, string name, float value)
        {
            string key = string.Format("{0}/float:{1}", GetBaseName(className, instanceName), name);

            EditorPrefs.SetFloat(key, value);
        }
예제 #28
0
        /// <summary>
        /// GUI event.
        /// </summary>
        private void OnGUI()
        {
            // Title style
            GUIStyle titleStyle = new GUIStyle(GUI.skin.label);

            titleStyle.alignment = TextAnchor.MiddleCenter;
            titleStyle.fontSize  = 14;
            titleStyle.fontStyle = FontStyle.Bold;

            // Title
            EditorGUILayout.Space();
            GUILayout.Label("MicDecode Calculation Settings", titleStyle);

            EditorGUILayout.Separator();

            // Audio sample resolution
            EditorGUILayout.Space();
            MicDecodeSettings.audioSamples = EditorGUILayout.IntPopup("Audio Sample Resolution", MicDecodeSettings.audioSamples, sampleResolutionsVal, sampleResolutions);
            EditorPrefs.SetInt("audioSamples", MicDecodeSettings.audioSamples);

            // Decibel reference
            EditorGUILayout.Space();
            MicDecodeSettings.decibelReference = EditorGUILayout.FloatField("Decibel Reference", MicDecodeSettings.decibelReference);
            EditorPrefs.SetFloat("decibelReference", MicDecodeSettings.decibelReference);

            // Decoding threshold
            EditorGUILayout.Space();
            MicDecodeSettings.decodeThreshold = EditorGUILayout.Slider("Decoding Threshold", MicDecodeSettings.decodeThreshold, 0.001f, 0.2f);
            EditorPrefs.SetFloat("decodeThreshold", MicDecodeSettings.decodeThreshold);

            EditorGUILayout.Separator();

            // Debug state
            EditorGUILayout.Space();
            MicDecodeSettings.debugState = (MicDecodeSettings.Debug)EditorGUILayout.EnumPopup("Debug", MicDecodeSettings.debugState);
            EditorPrefs.SetInt("debugState", (int)MicDecodeSettings.debugState);

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

            // Restore defaults
            if (GUILayout.Button("Restore Defaults"))
            {
                // Audio sample resolution
                MicDecodeSettings.audioSamples = 2048;
                EditorPrefs.SetInt("audioSamples", MicDecodeSettings.audioSamples);

                // Decibel reference
                MicDecodeSettings.decibelReference = 1f;
                EditorPrefs.SetFloat("decibelReference", MicDecodeSettings.decibelReference);

                // Decoding threshold
                MicDecodeSettings.decodeThreshold = 0.01f;
                EditorPrefs.SetFloat("decodeThreshold", MicDecodeSettings.decodeThreshold);

                // Debug state
                MicDecodeSettings.debugState = MicDecodeSettings.Debug.Off;
                EditorPrefs.SetInt("debugState", (int)MicDecodeSettings.debugState);
            }

            EditorGUILayout.Separator();

            // Footer
            EditorGUILayout.Space();
            GUILayout.Label("MicDecode v" + MicDecodeSettings.VERSION + " - Julian Schönbächler", EditorStyles.centeredGreyMiniLabel);
        }
예제 #29
0
    /// <summary>
    /// Save the specified float value in settings.
    /// </summary>

    static public void SetFloat(string name, float val)
    {
        EditorPrefs.SetFloat(name, val);
    }
예제 #30
0
        private void OnGUI()
        {
            scene = SceneManager.GetActiveScene().name;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Fog of War Baking Tool", EditorStyles.largeLabel);
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            LayerMask tempVisionMask = EditorGUILayout.MaskField("Vision Blocking Layers: ", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(visionMask), InternalEditorUtility.layers);

            visionMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempVisionMask);

            GUILayout.Space(5);

            LayerMask tempCamoMask = EditorGUILayout.MaskField("Camouflage layers: ", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(camoMask), InternalEditorUtility.layers);

            camoMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempCamoMask);

            if (scene != lastScene)
            {
                lastScene = scene;
                terrain   = null;
            }

            FOWLevelBakingInfo levelInfo = AssetDatabase.LoadAssetAtPath <FOWLevelBakingInfo>(LevelBakingInfoPath + scene + ".Asset");

            GUILayout.Space(10);
            Rect rect = EditorGUILayout.GetControlRect(false, 2);

            EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.5f));
            GUILayout.Space(10);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            if (levelInfo != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Baking Info:", EditorStyles.boldLabel);
                if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false)))
                {
                    AssetDatabase.DeleteAsset(LevelBakingInfoPath + scene + ".Asset");
                    return;
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);
                levelInfo.unsafeMode = EditorGUILayout.Toggle("Unsafe mode:", levelInfo.unsafeMode);
                GUILayout.Space(5);

                if (levelInfo.unsafeMode)
                {
                    levelInfo.sceneName        = EditorGUILayout.TextField("Scene name:", levelInfo.sceneName);
                    levelInfo.mapSize          = EditorGUILayout.IntField("Map size:", levelInfo.mapSize);
                    levelInfo.eyeHeight        = EditorGUILayout.FloatField("Eye height:", levelInfo.eyeHeight);
                    levelInfo.maxVisionRange   = EditorGUILayout.FloatField("Max vision range:", levelInfo.maxVisionRange);
                    levelInfo.tileSize         = EditorGUILayout.IntField("Tile size:", levelInfo.tileSize);
                    levelInfo.maxTerrainHeight = EditorGUILayout.FloatField("Max terrain height:", levelInfo.maxTerrainHeight);
                    levelInfo.terrainOffset    = EditorGUILayout.Vector3Field("Terrain offset:", levelInfo.terrainOffset);
                }
                else
                {
                    int maxMapSize = 128 * levelInfo.tileSize;
                    int minMapSize = 2 * levelInfo.tileSize;

                    levelInfo.sceneName      = EditorGUILayout.TextField("Scene name:", levelInfo.sceneName);
                    levelInfo.mapSize        = EditorGUILayout.IntSlider("Map size:", levelInfo.mapSize, minMapSize, maxMapSize);
                    levelInfo.eyeHeight      = EditorGUILayout.Slider("Eye height:", levelInfo.eyeHeight, 0.05f, 10);
                    levelInfo.maxVisionRange = EditorGUILayout.Slider("Max vision range:", levelInfo.maxVisionRange, 1, 150);
                    levelInfo.tileSize       = EditorGUILayout.IntSlider("Tile size:", levelInfo.tileSize, 1, 4);

                    if (levelInfo.tileSize == 3)
                    {
                        levelInfo.tileSize = 4;
                    }

                    levelInfo.maxTerrainHeight = EditorGUILayout.Slider("Max terrain height:", levelInfo.maxTerrainHeight, 1, 200);
                    levelInfo.terrainOffset    = EditorGUILayout.Vector3Field("Terrain offset:", levelInfo.terrainOffset);
                }

                GUILayout.Space(20);

                GUILayout.Label("Baked Data:", EditorStyles.boldLabel);
                levelInfo.filePath = EditorGUILayout.TextField("File path:", levelInfo.filePath);

                bool tileMapMismatch = levelInfo.mapSize % levelInfo.tileSize != 0;

                if (!File.Exists(levelInfo.filePath))
                {
                    GUILayout.Space(10);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("No file found in file path. Bake new?", EditorStyles.boldLabel);

                    EditorGUI.BeginDisabledGroup(tileMapMismatch);
                    if (GUILayout.Button("Bake", GUILayout.ExpandWidth(false)))
                    {
                        FOWBaker baker = new FOWBaker(levelInfo);
                        baker.BakeAndSaveData(visionMask, camoMask);
                        AssetDatabase.Refresh();
                    }
                    EditorGUI.EndDisabledGroup();
                    GUILayout.EndHorizontal();

                    if (tileMapMismatch)
                    {
                        GUILayout.Space(30);
                        GUILayout.Label("Map size must be dividable by tile size.", EditorStyles.miniBoldLabel);
                    }

                    GUILayout.Space(5);
                }
                else
                {
                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    long fileSize = new FileInfo(levelInfo.filePath).Length / 1024 / 1024;
                    GUILayout.Label("Size: " + fileSize + " MB");

                    EditorGUI.BeginDisabledGroup(tileMapMismatch);
                    if (GUILayout.Button("Re-bake", GUILayout.ExpandWidth(false)))
                    {
                        FOWBaker baker = new FOWBaker(levelInfo);
                        baker.BakeAndSaveData(visionMask, camoMask);
                        AssetDatabase.Refresh();
                    }
                    EditorGUI.EndDisabledGroup();

                    if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false)))
                    {
                        File.Delete(levelInfo.filePath);
                        AssetDatabase.Refresh();
                    }
                    GUILayout.EndHorizontal();

                    if (tileMapMismatch)
                    {
                        GUILayout.Space(30);
                        GUILayout.Label("Map size must be dividable by tile size.", EditorStyles.miniBoldLabel);
                    }

                    GUILayout.Space(5);
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("No baking info for scene '" + scene + "'", EditorStyles.boldLabel);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                terrain = EditorGUILayout.ObjectField("Terrain:", terrain, typeof(Terrain), true) as Terrain;

                EditorGUI.BeginDisabledGroup(terrain == null);
                if (GUILayout.Button("Add data", GUILayout.ExpandWidth(false)))
                {
                    levelInfo = CreateLevelBakingInfo(scene + ".Asset");
                }
                EditorGUI.EndDisabledGroup();
                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();

            if (GUI.changed)
            {
                EditorPrefs.SetInt("FOWLayerMask", visionMask);
                EditorPrefs.SetInt("CamoLayerMask", camoMask);
                if (levelInfo != null)
                {
                    EditorPrefs.SetFloat("LastEyeHeight", levelInfo.eyeHeight);
                    EditorPrefs.SetFloat("LastVisionRange", levelInfo.maxVisionRange);
                }
                EditorUtility.SetDirty(levelInfo);
            }
        }