コード例 #1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        var script = target as DayNightCycleManager;

        EditorGUILayout.Space();

        script.debugRotationSelected = EditorGUILayout.Foldout(script.debugRotationSelected, "Debug Rotation In Editor");
        if (script.debugRotationSelected)
        {
            script.debugRotationLength = EditorGUILayout.FloatField("Length Of One Debug Rotation: ", script.debugRotationLength);

            if (!script.DebugRotationActive)
            {
                if (GUILayout.Button("Start Rotation"))
                {
                    script.DebugRotationActive = true;
                    EditorCoroutine.StartEditorCoroutine(DebugRotation(script));
                }
            }
            else if (GUILayout.Button("Stop Rotation"))
            {
                script.DebugRotationActive = false;
            }
        }
    }
コード例 #2
0
    void DayNightGUI()
    {
        EditorGUI.indentLevel++;
        var dayNightManager = DayNightCycleManager.Instance;

        if (dayNightManager)
        {
            dayNightManager.debugRotationSelected = EditorGUILayout.Foldout(dayNightManager.debugRotationSelected, "Debug Auto Rotation In Editor");
            if (dayNightManager.debugRotationSelected)
            {
                EditorGUI.indentLevel++;
                dayNightManager.debugRotationLength = EditorGUILayout.FloatField("Debug Rotation Length: ", dayNightManager.debugRotationLength);

                if (!dayNightManager.DebugRotationActive)
                {
                    if (GUILayout.Button("Start Rotation"))
                    {
                        dayNightManager.DebugRotationActive = true;
                        EditorCoroutine.StartEditorCoroutine(DayNightCycleInspector.DebugRotation(dayNightManager));
                    }
                }
                else if (GUILayout.Button("Pause Rotation"))
                {
                    dayNightManager.DebugRotationActive = false;
                }
                EditorGUI.indentLevel--;
            }
        }
        EditorGUI.indentLevel--;
        EditorGUILayout.Separator();
    }
コード例 #3
0
    public static EditorCoroutine StartEditorCoroutine(IEnumerator _routine)
    {
        EditorCoroutine coroutine = new EditorCoroutine(_routine);

        coroutine.StartEditorCoroutine();
        return(coroutine);
    }
コード例 #4
0
 public virtual void DrawBuildButtons()
 {
     if (GUILayout.Button("Build"))
     {
         EditorCoroutine.StartEditorCoroutine(this.DoBuild(BuildSettings.PostBuildOption.OpenFolder));
     }
     if (GUILayout.Button("Build & Run"))
     {
         EditorCoroutine.StartEditorCoroutine(this.DoBuild(BuildSettings.PostBuildOption.OpenFolderAndRun));
     }
     if (GUILayout.Button("Sync To Global Build"))
     {
         this.SyncToGlobalBuild();
     }
 }
コード例 #5
0
        protected override void OnSPInspectorGUI()
        {
            base.OnSPInspectorGUI();

            if (GUILayout.Button("Build"))
            {
                if (EditorUtility.DisplayDialog("Build?", "Confirm that you want to perform a bulk build.", "Yes", "Cancel"))
                {
                    var settings = this.target as BulkBuildSettings;
                    if (settings == null)
                    {
                        return;
                    }

                    EditorCoroutine.StartEditorCoroutine(settings.BuildRoutine());
                }
            }
        }
コード例 #6
0
    // moho fbx import後に通過する処理
    void OnPostprocessModel(GameObject g)
    {
        // Only operate on FBX files
        if (assetPath.IndexOf(".fbx") == -1)
        {
            return;
        }

        if (!isMohoModel)
        {
            //Debug.Log("*** Not Moho ***");
            return;
        }

        //AnimationControllerを作成
        var filePath = System.IO.Path.GetDirectoryName(assetPath);

        filePath = filePath + "/" + g.name + "_Controller.controller";

        AnimatorController animCont = null;
        var asset = AssetDatabase.LoadAssetAtPath(filePath, typeof(AnimatorController)) as AnimatorController;

        if (asset == null)
        {
            animCont = AnimatorController.CreateAnimatorControllerAtPath(filePath);
            AssetDatabase.Refresh();
        }
        else
        {
            animCont = asset;
        }

        //いったん作ったAnimatorControllerのリンクを破棄してAssetDatabaseから読み込みしなおし
        //animCont = null;
        //animCont = AssetDatabase.LoadAssetAtPath(filePath, typeof(AnimatorController)) as AnimatorController;

        //TODO:AnimationClipをSteteにセットしたいがNullになる未調査

        /*{
         *  Debug.Log("AnimationClip Path>>" + ClipPath);
         *  AnimationClip tempClip = AssetDatabase.LoadAssetAtPath(ClipPath, typeof(AnimationClip)) as AnimationClip;
         *  var makeStateMachine = animCont.layers[0].stateMachine;
         *  Debug.Log(makeStateMachine + "/" + animCont + "/[" + tempClip.name + "]");
         *  var animState = makeStateMachine.AddState("DefaultMotion");
         *  animState.motion = tempClip;
         * }*/

        //Animatorはつけておきます
        Animator gAnim = g.AddComponent <Animator>();

        gAnim.runtimeAnimatorController = animCont;

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        Shader shader = Shader.Find("Moho/TransparentShader");

        if (shader == null)
        {
            return;
        }

        Renderer[] renderers           = g.GetComponentsInChildren <Renderer>();
        int        straightRenderOrder = 0;// shader.renderQueue;

        foreach (Renderer r in renderers)
        {
            int renderOrder = straightRenderOrder;
            if (r.name.Contains("|"))
            {
                string[] stringSeparators = new string[] { "|" };
                string[] parts            = r.name.Split(stringSeparators, StringSplitOptions.None);
                int      j;
                if (Int32.TryParse(parts[parts.Length - 1], out j))
                {
                    renderOrder += j;
                }
            }
            r.sharedMaterial.shader = shader; // apply an unlit shader
            //r.sharedMaterial.renderQueue = renderOrder; // set a fixed render order
            r.sharedMaterial.SetFloat("_CullMode", (float)UnityEngine.Rendering.CullMode.Off);
            r.sharedMaterial.SetFloat("_ZWrite", 0f);
            r.sharedMaterial.SetFloat("_OffsetFactor", -1f * renderOrder);
            r.sharedMaterial.SetFloat("_OffsetUnits", -1f * renderOrder);
            //straightRenderOrder++;


            Texture tex = r.sharedMaterial.GetTexture("_MainTex");
            if (tex == null)
            {
                Debug.LogError("r.sharedMaterial.GetTexture(_MainTex) が見つからなかった r:" + r);
                continue;
            }
            string          texPath = AssetDatabase.GetAssetPath(tex);
            TextureImporter _ti     = AssetImporter.GetAtPath(texPath) as TextureImporter;
            _ti.mipmapEnabled = false;
            _ti.wrapMode      = TextureWrapMode.Clamp;

            EditorUtility.SetDirty(_ti);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            AssetDatabase.ImportAsset(texPath, ImportAssetOptions.ForceUpdate);
        }

        //Import時に変なScaleが入っていた時はScale1に戻す
        //必要なら、Animationの方にScaleが入っているからこちらは見えるようにします
        Transform[] transforms = g.GetComponentsInChildren <Transform>();
        foreach (Transform T in transforms)
        {
            if (T.localScale.x < 0.00001f && T.localScale.y < 0.00001f && T.localScale.z < 0.00001f)
            {
                T.localScale = Vector3.one;
            }
        }

        Debug.Log("moho import処理完了待ち開始 assetPath:" + assetPath);// Assets/somewhere/x.fbx

        // 上で作成したいろいろなものがAssetDatabaseにセットされるので、その完了待ちをする。完了時処理とかもしこめる。
        var importedPathSource = assetPath.Split('/');
        var importedPathSourceWithoutFileName = new string[importedPathSource.Length - 1];

        for (var i = 0; i < importedPathSourceWithoutFileName.Length; i++)
        {
            importedPathSourceWithoutFileName[i] = importedPathSource[i];
        }
        var importedPath = string.Join("/", importedPathSourceWithoutFileName);

        // この時点で9ファイルある、これが10ファイルになる
        var fileCount = Directory.GetFiles(importedPath).Length;

        IEnumerator waitCor()
        {
            // assetImport処理が終わるまで待つ
            while (true)
            {
                var filePaths = Directory.GetFiles(importedPath);
                // foreach (var f in filePaths)
                // {
                //     Debug.Log("f:" + f);
                // }

                // TODO: 今のところは1ファイルでも増えてれば完了にしてる
                if (fileCount < filePaths.Length)
                {
                    break;
                }
                yield return(null);
            }


            var targetFBX = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;

            var FBXPath     = AssetDatabase.GetAssetPath(targetFBX);
            var path        = Path.GetDirectoryName(AssetDatabase.GetAssetOrScenePath(targetFBX));
            var projectName = Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetOrScenePath(targetFBX));

            var animFilePath = path + "/" + projectName + "_anim/Mainline.anim";
            var jsonFilePath = path + "/" + projectName + ".json";

            var animData = AssetDatabase.LoadAssetAtPath(animFilePath, typeof(AnimationClip)) as AnimationClip;

            if (File.Exists(jsonFilePath) || animData != null)
            {
                var jsonData = File.ReadAllText(jsonFilePath);
                MohoSmartWarpImporter.Run(projectName, FBXPath, targetFBX, jsonData, path, animData);
            }
            else
            {
                //animファイルか、Jsonファイルがありません
                Debug.LogError("情報が足りていません、以下を確認ください");
                Debug.LogError("FBXをReimportする");
                Debug.LogError("jsonファイルを作成する");
            }

            Debug.Log("import処理完了 assetPath:" + assetPath);
        };
        EditorCoroutine.StartEditorCoroutine(waitCor());
    }
コード例 #7
0
	public static EditorCoroutine StartEditorCoroutine( IEnumerator _routine )
	{
		EditorCoroutine coroutine = new EditorCoroutine(_routine);
		coroutine.StartEditorCoroutine();
		return coroutine;
	}
コード例 #8
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        var script = target as NoiseSettings;

        EditorGUILayout.Space();

        DisplayPreview = EditorGUILayout.Foldout(DisplayPreview, "Preview Noise Result");

        if (DisplayPreview)
        {
            if (!gridInitialized)
            {
                previewSeed = GetCurrentSeed();
                UpdateCheck(script);
                gridInitialized = true;
                EditorCoroutine.StartEditorCoroutine(CheckForUpdates(script));
            }

            var   lastRect         = GUILayoutUtility.GetLastRect();
            float previewPixelSize = (float)previewSize * previewScale;

            previewWindowRect = new Rect(new Vector2(lastRect.center.x - previewPixelSize / 2f, lastRect.yMin + 20), new Vector2(previewPixelSize, previewPixelSize));
            float previewOutputRange = 0f;
            if (script.passOperationType == NoiseSettings.PassOperation.ADD)
            {
                previewOutputRange = script.outputCurve.maxOutputValue - script.outputCurve.minOutputValue;
            }
            else if (script.passOperationType == NoiseSettings.PassOperation.MULTIPLY)
            {
                previewOutputRange = 1f;
            }

            NoisePreview.DrawNoise(script.debugPreviewGrid, previewWindowRect, previewOutputRange);
            GUILayout.Space(previewPixelSize + 5f);

            EditorGUI.indentLevel++;

            previewSeed = EditorGUILayout.IntField("Preview Seed: ", previewSeed);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Get Current Seed"))
            {
                previewSeed = GetCurrentSeed();
                GeneratePreview(script);
            }
            if (GUILayout.Button("Randomize Seed"))
            {
                previewSeed = CustomMathf.GetRandomSeed();
                GeneratePreview(script);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel--;
        }

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

        if (GUILayout.Button("--- Generate Terrain ---"))
        {
            GameObject.FindObjectOfType <TerrainGenerator>().GenerateMesh();
        }
    }