void UpdateCurve(string Label, SPCRJointDynamicsController Source, ref AnimationCurve Value)
 {
     Value = EditorGUILayout.CurveField(Label, Value);
 }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        var controller = target as SPCRJointDynamicsController;

        GUILayout.Space(8);
        controller.Name = EditorGUILayout.TextField("名称", controller.Name);

        _Opened_BaseSettings = Foldout(_Opened_BaseSettings, "基本設定", new Color(1.0f, 0.7f, 1.0f));
        if (_Opened_BaseSettings)
        {
            var _RootTransform = (Transform)EditorGUILayout.ObjectField(new GUIContent("親Transform"), controller._RootTransform, typeof(Transform), true);
            if (controller._RootTransform != _RootTransform)
            {
                controller._RootTransform = _RootTransform;
                EditorUtility.SetDirty(controller);
            }

            if (GUILayout.Button("ルートの点群自動検出", GUILayout.Height(22.0f)))
            {
                SearchRootPoints(controller);
            }

            if (EditorGUILayout.PropertyField(serializedObject.FindProperty("_RootPointTbl"), new GUIContent("ルートの点群"), true))
            {
                EditorUtility.SetDirty(controller);
            }
            GUILayout.Space(5);

            if (EditorGUILayout.PropertyField(serializedObject.FindProperty("_ColliderTbl"), new GUIContent("コライダー"), true))
            {
                EditorUtility.SetDirty(controller);
            }
            if (EditorGUILayout.PropertyField(serializedObject.FindProperty("_PointGrabberTbl"), new GUIContent("グラバー"), true))
            {
                EditorUtility.SetDirty(controller);
            }
        }

        _Opened_PhysicsSettings = Foldout(_Opened_PhysicsSettings, "物理設定", new Color(1.0f, 1.0f, 0.7f));
        if (_Opened_PhysicsSettings)
        {
            var _UpdateTiming = (SPCRJointDynamicsController.UpdateTiming)EditorGUILayout.EnumPopup("更新タイミング", controller._UpdateTiming);
            if (controller._UpdateTiming != _UpdateTiming)
            {
                controller._UpdateTiming = _UpdateTiming;
                EditorUtility.SetDirty(controller);
            }
            UpdateIntSlider("演算繰り返し回数", controller, ref controller._Relaxation, 1, 16);
            UpdateIntSlider("演算分割数", controller, ref controller._SubSteps, 1, 16);

            GUILayout.Space(8);
            UpdateToggle("物理リセットを拒否", controller, ref controller._IsCancelResetPhysics);
            GUILayout.Space(8);
            UpdateToggle("質点とコライダーの衝突判定をする", controller, ref controller._IsEnableColliderCollision);
            GUILayout.Space(8);
            UpdateToggle("質点と床の衝突判定をする", controller, ref controller._IsEnableFloorCollision);
            if (controller._IsEnableFloorCollision)
            {
                UpdateFloat("床の高さ", controller, ref controller._FloorHeight);
            }
            GUILayout.Space(8);
            UpdateIntSlider("詳細な衝突判定の最大分割数", controller, ref controller._DetailHitDivideMax, 0, 16);

            GUILayout.Space(8);
            UpdateFloat("ルートの最大移動距離", controller, ref controller._RootSlideLimit);
            UpdateFloat("ルートの最大回転角", controller, ref controller._RootRotateLimit);

            GUILayout.Space(8);
            UpdateSlider("バネ係数", controller, ref controller._SpringK, 0.0f, 1.0f);

            GUILayout.Space(8);
            UpdateVector3("重力", controller, ref controller._Gravity);
            UpdateVector3("風力", controller, ref controller._WindForce);

            GUILayout.Space(8);
            UpdateCurve("質量", controller, ref controller._MassScaleCurve);
            UpdateCurve("重力", controller, ref controller._GravityScaleCurve);
            UpdateCurve("空気抵抗", controller, ref controller._ResistanceCurve);
            UpdateCurve("硬さ", controller, ref controller._HardnessCurve);
            UpdateCurve("摩擦", controller, ref controller._FrictionCurve);
        }

        _Opened_ConstraintSettings = Foldout(_Opened_ConstraintSettings, "拘束設定", new Color(0.7f, 1.0f, 1.0f));
        if (_Opened_ConstraintSettings)
        {
            EditorGUILayout.LabelField("=============== スライダージョイント長さ(一括)");
            UpdateCurve("水平方向への伸び", controller, ref controller._SliderJointLengthCurve);
            UpdateCurve("ジョイント内バネ", controller, ref controller._SliderJointSpringCurve);

            GUILayout.Space(5);
            EditorGUILayout.LabelField("=============== 拘束(一括)");
            UpdateCurve("伸びた時縮む力", controller, ref controller._AllShrinkScaleCurve);
            UpdateCurve("縮む時伸びる力", controller, ref controller._AllStretchScaleCurve);

            GUILayout.Space(5);
            EditorGUILayout.LabelField("=============== 構成拘束(垂直)");
            if (controller._IsComputeStructuralVertical)
            {
                UpdateSlider("伸びた時縮む力", controller, ref controller._StructuralShrinkVertical, 0.0f, 1.0f);
                UpdateSlider("縮む時伸びる力", controller, ref controller._StructuralStretchVertical, 0.0f, 1.0f);
                GUILayout.Space(5);
                UpdateCurve("伸びた時縮む力", controller, ref controller._StructuralShrinkVerticalScaleCurve);
                UpdateCurve("縮む時伸びる力", controller, ref controller._StructuralStretchVerticalScaleCurve);
                GUILayout.Space(5);
                UpdateToggle("伸びた時縮む力(一括設定)", controller, ref controller._IsAllStructuralShrinkVertical);
                UpdateToggle("縮む時伸びる力(一括設定)", controller, ref controller._IsAllStructuralStretchVertical);
            }
            else
            {
                EditorGUILayout.LabelField("※ 無効 ※");
            }

            EditorGUILayout.LabelField("=============== 構成拘束(水平)");
            if (controller._IsComputeStructuralHorizontal)
            {
                UpdateSlider("伸びた時縮む力", controller, ref controller._StructuralShrinkHorizontal, 0.0f, 1.0f);
                UpdateSlider("縮む時伸びる力", controller, ref controller._StructuralStretchHorizontal, 0.0f, 1.0f);
                GUILayout.Space(5);
                UpdateCurve("伸びた時縮む力", controller, ref controller._StructuralShrinkHorizontalScaleCurve);
                UpdateCurve("縮む時伸びる力", controller, ref controller._StructuralStretchHorizontalScaleCurve);
                GUILayout.Space(5);
                UpdateToggle("伸びた時縮む力(一括設定)", controller, ref controller._IsAllStructuralShrinkHorizontal);
                UpdateToggle("縮む時伸びる力(一括設定)", controller, ref controller._IsAllStructuralStretchHorizontal);
            }
            else
            {
                EditorGUILayout.LabelField("※ 無効 ※");
            }

            EditorGUILayout.LabelField("=============== せん断拘束");
            if (controller._IsComputeShear)
            {
                UpdateSlider("伸びた時縮む力", controller, ref controller._ShearShrink, 0.0f, 1.0f);
                UpdateSlider("縮む時伸びる力", controller, ref controller._ShearStretch, 0.0f, 1.0f);
                GUILayout.Space(5);
                UpdateCurve("伸びた時縮む力", controller, ref controller._ShearShrinkScaleCurve);
                UpdateCurve("縮む時伸びる力", controller, ref controller._ShearStretchScaleCurve);
                GUILayout.Space(5);
                UpdateToggle("伸びた時縮む力(一括設定)", controller, ref controller._IsAllShearShrink);
                UpdateToggle("縮む時伸びる力(一括設定)", controller, ref controller._IsAllShearStretch);
            }
            else
            {
                EditorGUILayout.LabelField("※ 無効 ※");
            }

            EditorGUILayout.LabelField("=============== 曲げ拘束(垂直)");
            if (controller._IsComputeBendingVertical)
            {
                UpdateSlider("伸びた時縮む力", controller, ref controller._BendingingShrinkVertical, 0.0f, 1.0f);
                UpdateSlider("縮む時伸びる力", controller, ref controller._BendingingStretchVertical, 0.0f, 1.0f);
                GUILayout.Space(5);
                UpdateCurve("伸びた時縮む力", controller, ref controller._BendingShrinkVerticalScaleCurve);
                UpdateCurve("縮む時伸びる力", controller, ref controller._BendingStretchVerticalScaleCurve);
                GUILayout.Space(5);
                UpdateToggle("伸びた時縮む力(一括設定)", controller, ref controller._IsAllBendingingShrinkVertical);
                UpdateToggle("縮む時伸びる力(一括設定)", controller, ref controller._IsAllBendingingStretchVertical);
            }
            else
            {
                EditorGUILayout.LabelField("※ 無効 ※");
            }

            EditorGUILayout.LabelField("=============== 曲げ拘束(水平)");
            if (controller._IsComputeBendingHorizontal)
            {
                UpdateSlider("伸びた時縮む力", controller, ref controller._BendingingShrinkHorizontal, 0.0f, 1.0f);
                UpdateSlider("縮む時伸びる力", controller, ref controller._BendingingStretchHorizontal, 0.0f, 1.0f);
                GUILayout.Space(5);
                UpdateCurve("伸びた時縮む力", controller, ref controller._BendingShrinkHorizontalScaleCurve);
                UpdateCurve("縮む時伸びる力", controller, ref controller._BendingStretchHorizontalScaleCurve);
                GUILayout.Space(5);
                UpdateToggle("伸びた時縮む力(一括設定)", controller, ref controller._IsAllBendingingShrinkHorizontal);
                UpdateToggle("縮む時伸びる力(一括設定)", controller, ref controller._IsAllBendingingStretchHorizontal);
            }
            else
            {
                EditorGUILayout.LabelField("※ 無効 ※");
            }
        }

        _Opened_AngleLockSettings = Foldout(_Opened_AngleLockSettings, "角度制限", new Color(0.7f, 0.7f, 1.0f));
        if (_Opened_AngleLockSettings)
        {
            controller._UseLimitAngles = EditorGUILayout.Toggle("角度制限", controller._UseLimitAngles);
            if (controller._UseLimitAngles)
            {
                controller._LimitAngle      = EditorGUILayout.IntSlider("角度制限", controller._LimitAngle, 0, 180);
                controller._LimitPowerCurve = EditorGUILayout.CurveField("制限力", controller._LimitPowerCurve);
                controller._LimitFromRoot   = EditorGUILayout.Toggle("ルートから角度制限", controller._LimitFromRoot);
            }
        }

        _Opened_OptionSettings = Foldout(_Opened_OptionSettings, "オプション", new Color(0.7f, 1.0f, 0.7f));
        if (_Opened_OptionSettings)
        {
            if (GUILayout.Button("物理初期化"))
            {
                controller.ResetPhysics(0.3f);
            }

            GUILayout.Space(8);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_IsPaused"), new GUIContent("一時停止"), true);

            Titlebar("デバッグ表示", new Color(0.7f, 1.0f, 1.0f));
            UpdateToggle("垂直構造", controller, ref controller._IsDebugDraw_StructuralVertical);
            UpdateToggle("水平構造", controller, ref controller._IsDebugDraw_StructuralHorizontal);
            UpdateToggle("せん断", controller, ref controller._IsDebugDraw_Shear);
            UpdateToggle("垂直曲げ", controller, ref controller._IsDebugDraw_BendingVertical);
            UpdateToggle("水平曲げ", controller, ref controller._IsDebugDraw_BendingHorizontal);
            UpdateToggle("実行中のコリジョン情報", controller, ref controller._IsDebugDraw_RuntimeColliderBounds);
        }

        _Opened_PreSettings = Foldout(_Opened_PreSettings, "事前設定", new Color(1.0f, 0.7f, 0.7f));
        if (_Opened_PreSettings)
        {
            UpdateToggle("拘束のループ", controller, ref controller._IsLoopRootPoints);
            GUILayout.Space(5);
            EditorGUILayout.LabelField("=============== 拘束の有無");
            UpdateToggle("拘束:垂直構造", controller, ref controller._IsComputeStructuralVertical);
            UpdateToggle("拘束:水平構造", controller, ref controller._IsComputeStructuralHorizontal);
            UpdateToggle("拘束:せん断", controller, ref controller._IsComputeShear);
            UpdateToggle("拘束:垂直曲げ", controller, ref controller._IsComputeBendingVertical);
            UpdateToggle("拘束:水平曲げ", controller, ref controller._IsComputeBendingHorizontal);
            GUILayout.Space(5);
            EditorGUILayout.LabelField("=============== コリジョン");
            UpdateToggle("衝突:垂直構造", controller, ref controller._IsCollideStructuralVertical);
            UpdateToggle("衝突:水平構造", controller, ref controller._IsCollideStructuralHorizontal);
            UpdateToggle("衝突:せん断", controller, ref controller._IsCollideShear);
            UpdateToggle("衝突:垂直曲げ", controller, ref controller._IsCollideBendingVertical);
            UpdateToggle("衝突:水平曲げ", controller, ref controller._IsCollideBendingHorizontal);
            GUILayout.Space(10);

            if (GUILayout.Button("自動設定"))
            {
                controller.UpdateJointConnection();
                EditorUtility.SetDirty(controller);
            }
            if (GUILayout.Button("自動設定(近ポイント自動検索XYZ)"))
            {
                SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXYZ);
                controller.UpdateJointConnection();
                EditorUtility.SetDirty(controller);
            }
            if (GUILayout.Button("自動設定(近ポイント自動検索XZ)"))
            {
                SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXZ);
                controller.UpdateJointConnection();
                EditorUtility.SetDirty(controller);
            }
            if (GUILayout.Button("自動設定(近ポイント自動検索XYZ:先端終端固定)"))
            {
                SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXYZ_FixedBeginEnd);
                controller.UpdateJointConnection();
                EditorUtility.SetDirty(controller);
            }
            if (GUILayout.Button("自動設定(近ポイント自動検索XZ:先端終端固定)"))
            {
                SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXZ_FixedBeginEnd);
                controller.UpdateJointConnection();
                EditorUtility.SetDirty(controller);
            }
            if (GUILayout.Button("拘束長さ再計算"))
            {
                controller.UpdateJointDistance();
                EditorUtility.SetDirty(controller);
            }
            {
                var bgColor      = GUI.backgroundColor;
                var contentColor = GUI.contentColor;
                GUI.contentColor    = Color.yellow;
                GUI.backgroundColor = new Color(1.0f, 0.5f, 0.5f);
                if (GUILayout.Button("拘束の設定を破棄"))
                {
                    controller.DeleteJointConnection();
                    EditorUtility.SetDirty(controller);
                }
                GUI.backgroundColor = bgColor;
                GUI.contentColor    = contentColor;
            }

            Titlebar("設定保存", new Color(1.0f, 0.7f, 0.7f));
            if (GUILayout.Button("設定を保存する"))
            {
                SPCRJointSettingLocalSave.Save(controller);
            }
            if (GUILayout.Button("設定をロードする"))
            {
                SPCRJointSettingLocalSave.Load(controller);
            }

            GUILayout.Space(5);

            Titlebar("細分化", new Color(0.7f, 1.0f, 0.7f));
            if (PrefabUtility.IsPartOfAnyPrefab(controller.gameObject))
            {
                EditorGUILayout.HelpBox("UnpackされていないPrefabは細分化できません", MessageType.Warning);
            }
            else
            {
                if (GUILayout.Button("垂直の拘束を挿入"))
                {
                    SubdivideVerticalChain(controller, 1);
                    EditorUtility.SetDirty(controller);
                }
                if (GUILayout.Button("水平の拘束を挿入"))
                {
                    SubdivideHorizontalChain(controller, 1);
                    EditorUtility.SetDirty(controller);
                }
                if (controller._SubDivInsertedPoints.Count > 0)
                {
                    if (GUILayout.Button("細分化を元に戻す"))
                    {
                        RemoveInsertedPoints(controller);
                        EditorUtility.SetDirty(controller);
                    }
                    {
                        var bgColor      = GUI.backgroundColor;
                        var contentColor = GUI.contentColor;
                        GUI.contentColor    = Color.yellow;
                        GUI.backgroundColor = new Color(0.6f, 0.0f, 0.0f);
                        if (GUILayout.Button("細分化の確定"))
                        {
                            PurgeSubdivideOriginalInfo(controller);
                            EditorUtility.SetDirty(controller);
                        }
                        GUI.backgroundColor = bgColor;
                        GUI.contentColor    = contentColor;
                    }
                    // EditorGUILayout.PropertyField(serializedObject.FindProperty("_SubDivInsertedPoints"), new GUIContent("追加された点群"), true);
                    // EditorGUILayout.PropertyField(serializedObject.FindProperty("_SubDivOriginalPoints"), new GUIContent("オリジナルの点群"), true);

                    {
                        var message = string.Format(
                            "分割後には自動設定を行ってください\nオリジナルの点:{0}個\n追加された点:{1}個",
                            controller._SubDivOriginalPoints.Count,
                            controller._SubDivInsertedPoints.Count);
                        EditorGUILayout.HelpBox(message, MessageType.Warning);
                    }
                }
            }
        }

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

        serializedObject.ApplyModifiedProperties();
    }
Exemple #3
0
    public void DisplayGUI()
    {
        MegaLoftLayerScatterSimple layer = (MegaLoftLayerScatterSimple)target;

        MegaShapeLoftEditor.PushCols();

        GUI.color           = Color.white;
        GUI.backgroundColor = layer.paramcol;
        GUI.contentColor    = Color.white;

        EditorGUILayout.BeginVertical("TextArea");

        SetLimits(layer.gameObject);
        //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>();

        layer.LayerName    = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName);
        layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled);
        layer.paramcol     = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol);

        if (layer.LayerEnabled)
        {
            layer.Lock = EditorGUILayout.Toggle(MegaToolTip.Lock, layer.Lock);

            if (!layer.Lock)
            {
                layer.scatterMesh = (Mesh)EditorGUILayout.ObjectField("Scatter Mesh", layer.scatterMesh, typeof(Mesh), true);
                layer.material    = (Material)EditorGUILayout.ObjectField("Material", layer.material, typeof(Material), true);
                layer.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", layer.surfaceLoft, typeof(MegaShapeLoft), true);
                //layer.surfaceLayer = EditorGUILayout.Popup("Layer", layer.surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1;
                int surfaceLayer = MegaShapeUtils.FindLayer(layer.surfaceLoft, layer.surfaceLayer);
                surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1;
                if (layer.surfaceLoft)
                {
                    for (int i = 0; i < layer.surfaceLoft.Layers.Length; i++)
                    {
                        //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) )
                        if (layer.surfaceLoft.Layers[i] is MegaLoftLayerSimple)
                        {
                            if (surfaceLayer == 0)
                            {
                                layer.surfaceLayer = i;
                                break;
                            }

                            surfaceLayer--;
                        }
                    }
                }
                else
                {
                    layer.surfaceLayer = surfaceLayer;
                }

                layer.start   = EditorGUILayout.Slider(MegaToolTip.StartSurface, layer.start, sl, sh);
                layer.length  = EditorGUILayout.Slider(MegaToolTip.LengthSurface, layer.length, ll, lh);
                layer.cstart  = EditorGUILayout.Slider(MegaToolTip.CrossStartSurface, layer.cstart, csl, csh);
                layer.clength = EditorGUILayout.Slider(MegaToolTip.CrossLengthSurface, layer.clength, cll, clh);

                layer.CalcUp    = EditorGUILayout.Toggle("Calc Up", layer.CalcUp);
                layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof);

                layer.Count = EditorGUILayout.IntField("Count", layer.Count);

                layer.Seed   = EditorGUILayout.IntField("Seed", layer.Seed);
                layer.Offset = EditorGUILayout.Vector3Field("Offset", layer.Offset);
                layer.rot    = EditorGUILayout.Vector3Field("Rotate", layer.rot);
                layer.scale  = EditorGUILayout.Vector3Field("Scale", layer.scale);

                layer.rotRange      = EditorGUILayout.Vector3Field("Rand Rotate", layer.rotRange);
                layer.scaleRangeMin = EditorGUILayout.Vector3Field("Rnd Scale Min", layer.scaleRangeMin);
                layer.scaleRangeMax = EditorGUILayout.Vector3Field("Rnd Scale Max", layer.scaleRangeMax);

                layer.tangent = EditorGUILayout.FloatField("Tangent", layer.tangent);
                layer.axis    = (MegaAxis)EditorGUILayout.EnumPopup("Axis", layer.axis);

                // Advanced
                layer.GlobalScale = EditorGUILayout.FloatField("Scale", layer.GlobalScale);

                // Start Info
                EditorGUILayout.BeginVertical("TextArea");
                layer.Alpha  = EditorGUILayout.Slider("Alpha", layer.Alpha, 0.0f, 1.0f);
                layer.CAlpha = EditorGUILayout.Slider("Cross Alpha", layer.CAlpha, 0.0f, 1.0f);
                layer.Speed  = EditorGUILayout.FloatField("Speed", layer.Speed);

                layer.useDensity = EditorGUILayout.BeginToggleGroup("Use Density", layer.useDensity);
                layer.density    = EditorGUILayout.CurveField("Density", layer.density, Color.green, new Rect(0.0f, 0.0f, 1.0f, 1.0f));
                EditorGUILayout.EndToggleGroup();
                EditorGUILayout.EndVertical();
            }

            //EditorGUILayout.EndVertical();
            //MegaShapeLoftEditor.PopCols();
        }
        EditorGUILayout.EndVertical();
        MegaShapeLoftEditor.PopCols();
    }
Exemple #4
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        var controller = target as SPCRJointDynamicsController;

        GUILayout.Space(8);
        controller.Name = EditorGUILayout.TextField("名称", controller.Name);

        Titlebar("基本設定", new Color(0.7f, 1.0f, 0.7f));
        controller._RootTransform = (Transform)EditorGUILayout.ObjectField(new GUIContent("親Transform"), controller._RootTransform, typeof(Transform), true);

        if (GUILayout.Button("ルートの点群自動検出", GUILayout.Height(22.0f)))
        {
            SearchRootPoints(controller);
        }
        EditorGUILayout.PropertyField(serializedObject.FindProperty("_RootPointTbl"), new GUIContent("ルートの点群"), true);
        GUILayout.Space(5);

        EditorGUILayout.PropertyField(serializedObject.FindProperty("_ColliderTbl"), new GUIContent("コライダー"), true);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("_PointGrabberTbl"), new GUIContent("グラバー"), true);

        Titlebar("物理設定", new Color(0.7f, 1.0f, 0.7f));

        controller._UpdateTiming = (SPCRJointDynamicsController.UpdateTiming)EditorGUILayout.EnumPopup("更新タイミング", controller._UpdateTiming);
        controller._Relaxation   = EditorGUILayout.IntSlider("演算繰り返し回数", controller._Relaxation, 1, 16);

        GUILayout.Space(8);
        controller._IsCancelResetPhysics = EditorGUILayout.Toggle("物理リセットを拒否", controller._IsCancelResetPhysics);
        GUILayout.Space(8);
        controller._IsEnableColliderCollision = EditorGUILayout.Toggle("質点とコライダーの衝突判定をする", controller._IsEnableColliderCollision);
        GUILayout.Space(8);
        controller._IsEnableFloorCollision = EditorGUILayout.Toggle("質点と床の衝突判定をする", controller._IsEnableFloorCollision);
        if (controller._IsEnableFloorCollision)
        {
            controller._FloorHeight = EditorGUILayout.FloatField("床の高さ", controller._FloorHeight);
        }

        GUILayout.Space(8);
        controller._SpringK = EditorGUILayout.Slider("バネ係数", controller._SpringK, 0.0f, 1.0f);

        GUILayout.Space(8);
        controller._Gravity   = EditorGUILayout.Vector3Field("重力", controller._Gravity);
        controller._WindForce = EditorGUILayout.Vector3Field("風力", controller._WindForce);

        GUILayout.Space(8);
        controller._MassScaleCurve    = EditorGUILayout.CurveField("質量", controller._MassScaleCurve);
        controller._GravityScaleCurve = EditorGUILayout.CurveField("重力", controller._GravityScaleCurve);
        controller._ResistanceCurve   = EditorGUILayout.CurveField("空気抵抗", controller._ResistanceCurve);
        controller._HardnessCurve     = EditorGUILayout.CurveField("硬さ", controller._HardnessCurve);
        controller._FrictionCurve     = EditorGUILayout.CurveField("摩擦", controller._FrictionCurve);

        Titlebar("拘束設定", new Color(0.7f, 1.0f, 0.7f));
        EditorGUILayout.LabelField("=============== 拘束(一括)");
        controller._AllShrinkScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._AllShrinkScaleCurve);
        controller._AllStretchScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._AllStretchScaleCurve);
        GUILayout.Space(5);
        EditorGUILayout.LabelField("=============== 構成拘束(垂直)");
        if (controller._IsComputeStructuralVertical)
        {
            controller._StructuralShrinkVertical  = EditorGUILayout.Slider("伸びた時縮む力", controller._StructuralShrinkVertical, 0.0f, 1.0f);
            controller._StructuralStretchVertical = EditorGUILayout.Slider("縮む時伸びる力", controller._StructuralStretchVertical, 0.0f, 1.0f);
            GUILayout.Space(5);
            controller._StructuralShrinkVerticalScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._StructuralShrinkVerticalScaleCurve);
            controller._StructuralStretchVerticalScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._StructuralStretchVerticalScaleCurve);
            GUILayout.Space(5);
            controller._IsAllStructuralShrinkVertical  = EditorGUILayout.Toggle("伸びた時縮む力(一括設定)", controller._IsAllStructuralShrinkVertical);
            controller._IsAllStructuralStretchVertical = EditorGUILayout.Toggle("縮む時伸びる力(一括設定)", controller._IsAllStructuralStretchVertical);
        }
        else
        {
            EditorGUILayout.LabelField("※ 無効 ※");
        }

        EditorGUILayout.LabelField("=============== 構成拘束(水平)");
        if (controller._IsComputeStructuralHorizontal)
        {
            controller._StructuralShrinkHorizontal  = EditorGUILayout.Slider("伸びた時縮む力", controller._StructuralShrinkHorizontal, 0.0f, 1.0f);
            controller._StructuralStretchHorizontal = EditorGUILayout.Slider("縮む時伸びる力", controller._StructuralStretchHorizontal, 0.0f, 1.0f);
            GUILayout.Space(5);
            controller._StructuralShrinkHorizontalScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._StructuralShrinkHorizontalScaleCurve);
            controller._StructuralStretchHorizontalScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._StructuralStretchHorizontalScaleCurve);
            GUILayout.Space(5);
            controller._IsAllStructuralShrinkHorizontal  = EditorGUILayout.Toggle("伸びた時縮む力(一括設定)", controller._IsAllStructuralShrinkHorizontal);
            controller._IsAllStructuralStretchHorizontal = EditorGUILayout.Toggle("縮む時伸びる力(一括設定)", controller._IsAllStructuralStretchHorizontal);
        }
        else
        {
            EditorGUILayout.LabelField("※ 無効 ※");
        }

        EditorGUILayout.LabelField("=============== せん断拘束");
        if (controller._IsComputeShear)
        {
            controller._ShearShrink  = EditorGUILayout.Slider("伸びた時縮む力", controller._ShearShrink, 0.0f, 1.0f);
            controller._ShearStretch = EditorGUILayout.Slider("縮む時伸びる力", controller._ShearStretch, 0.0f, 1.0f);
            GUILayout.Space(5);
            controller._ShearShrinkScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._ShearShrinkScaleCurve);
            controller._ShearStretchScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._ShearStretchScaleCurve);
            GUILayout.Space(5);
            controller._IsAllShearShrink  = EditorGUILayout.Toggle("伸びた時縮む力(一括設定)", controller._IsAllShearShrink);
            controller._IsAllShearStretch = EditorGUILayout.Toggle("縮む時伸びる力(一括設定)", controller._IsAllShearStretch);
        }
        else
        {
            EditorGUILayout.LabelField("※ 無効 ※");
        }

        EditorGUILayout.LabelField("=============== 曲げ拘束(垂直)");
        if (controller._IsComputeBendingVertical)
        {
            controller._BendingingShrinkVertical  = EditorGUILayout.Slider("伸びた時縮む力", controller._BendingingShrinkVertical, 0.0f, 1.0f);
            controller._BendingingStretchVertical = EditorGUILayout.Slider("縮む時伸びる力", controller._BendingingStretchVertical, 0.0f, 1.0f);
            GUILayout.Space(5);
            controller._BendingShrinkVerticalScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._BendingShrinkVerticalScaleCurve);
            controller._BendingStretchVerticalScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._BendingStretchVerticalScaleCurve);
            GUILayout.Space(5);
            controller._IsAllBendingingShrinkVertical  = EditorGUILayout.Toggle("伸びた時縮む力(一括設定)", controller._IsAllBendingingShrinkVertical);
            controller._IsAllBendingingStretchVertical = EditorGUILayout.Toggle("縮む時伸びる力(一括設定)", controller._IsAllBendingingStretchVertical);
        }
        else
        {
            EditorGUILayout.LabelField("※ 無効 ※");
        }

        EditorGUILayout.LabelField("=============== 曲げ拘束(水平)");
        if (controller._IsComputeBendingHorizontal)
        {
            controller._BendingingShrinkHorizontal  = EditorGUILayout.Slider("伸びた時縮む力", controller._BendingingShrinkHorizontal, 0.0f, 1.0f);
            controller._BendingingStretchHorizontal = EditorGUILayout.Slider("縮む時伸びる力", controller._BendingingStretchHorizontal, 0.0f, 1.0f);
            GUILayout.Space(5);
            controller._BendingShrinkHorizontalScaleCurve  = EditorGUILayout.CurveField("伸びた時縮む力", controller._BendingShrinkHorizontalScaleCurve);
            controller._BendingStretchHorizontalScaleCurve = EditorGUILayout.CurveField("縮む時伸びる力", controller._BendingStretchHorizontalScaleCurve);
            GUILayout.Space(5);
            controller._IsAllBendingingShrinkHorizontal  = EditorGUILayout.Toggle("伸びた時縮む力(一括設定)", controller._IsAllBendingingShrinkHorizontal);
            controller._IsAllBendingingStretchHorizontal = EditorGUILayout.Toggle("縮む時伸びる力(一括設定)", controller._IsAllBendingingStretchHorizontal);
        }
        else
        {
            EditorGUILayout.LabelField("※ 無効 ※");
        }

        Titlebar("オプション", new Color(0.7f, 1.0f, 0.7f));
        if (GUILayout.Button("物理初期化"))
        {
            controller.ResetPhysics(0.3f);
        }

        Titlebar("デバッグ表示", new Color(0.7f, 1.0f, 1.0f));
        controller._IsDebugDraw_StructuralVertical   = EditorGUILayout.Toggle("垂直構造", controller._IsDebugDraw_StructuralVertical);
        controller._IsDebugDraw_StructuralHorizontal = EditorGUILayout.Toggle("水平構造", controller._IsDebugDraw_StructuralHorizontal);
        controller._IsDebugDraw_Shear = EditorGUILayout.Toggle("せん断", controller._IsDebugDraw_Shear);

        Titlebar("事前設定", new Color(1.0f, 1.0f, 0.7f));
        controller._IsLoopRootPoints = EditorGUILayout.Toggle("拘束のループ", controller._IsLoopRootPoints);
        GUILayout.Space(5);
        EditorGUILayout.LabelField("=============== 拘束の有無");
        controller._IsComputeStructuralVertical   = EditorGUILayout.Toggle("拘束:垂直構造", controller._IsComputeStructuralVertical);
        controller._IsComputeStructuralHorizontal = EditorGUILayout.Toggle("拘束:水平構造", controller._IsComputeStructuralHorizontal);
        controller._IsComputeShear             = EditorGUILayout.Toggle("拘束:せん断", controller._IsComputeShear);
        controller._IsComputeBendingVertical   = EditorGUILayout.Toggle("拘束:垂直曲げ", controller._IsComputeBendingVertical);
        controller._IsComputeBendingHorizontal = EditorGUILayout.Toggle("拘束:水平曲げ", controller._IsComputeBendingHorizontal);
        GUILayout.Space(5);
        EditorGUILayout.LabelField("=============== コリジョン");
        controller._IsCollideStructuralVertical   = EditorGUILayout.Toggle("衝突:垂直構造", controller._IsCollideStructuralVertical);
        controller._IsCollideStructuralHorizontal = EditorGUILayout.Toggle("衝突:水平構造", controller._IsCollideStructuralHorizontal);
        controller._IsCollideShear             = EditorGUILayout.Toggle("衝突:せん断", controller._IsCollideShear);
        controller._IsCollideBendingVertical   = EditorGUILayout.Toggle("衝突:垂直曲げ", controller._IsCollideBendingVertical);
        controller._IsCollideBendingHorizontal = EditorGUILayout.Toggle("衝突:水平曲げ", controller._IsCollideBendingHorizontal);
        GUILayout.Space(10);

        if (GUILayout.Button("自動設定"))
        {
            controller.UpdateJointConnection();
            EditorUtility.SetDirty(controller);
        }
        if (GUILayout.Button("自動設定(近ポイント自動検索XYZ)"))
        {
            SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXYZ);
            controller.UpdateJointConnection();
            EditorUtility.SetDirty(controller);
        }
        if (GUILayout.Button("自動設定(近ポイント自動検索XZ)"))
        {
            SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXZ);
            controller.UpdateJointConnection();
            EditorUtility.SetDirty(controller);
        }
        if (GUILayout.Button("自動設定(近ポイント自動検索XYZ:先端終端固定)"))
        {
            SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXYZ_FixedBeginEnd);
            controller.UpdateJointConnection();
            EditorUtility.SetDirty(controller);
        }
        if (GUILayout.Button("自動設定(近ポイント自動検索XZ:先端終端固定)"))
        {
            SortConstraintsHorizontalRoot(controller, UpdateJointConnectionType.SortNearPointXZ_FixedBeginEnd);
            controller.UpdateJointConnection();
            EditorUtility.SetDirty(controller);
        }
        if (GUILayout.Button("拘束長さ再計算"))
        {
            controller.UpdateJointDistance();
            EditorUtility.SetDirty(controller);
        }

        Titlebar("拡張設定", new Color(1.0f, 0.7f, 0.7f));
        GUILayout.Space(3);
        _SubdivisionJointCountH = EditorGUILayout.IntSlider("水平骨分割数", _SubdivisionJointCountH, 2, 256);
        _SubdivisionJointCountV = EditorGUILayout.IntSlider("垂直骨分割数", _SubdivisionJointCountV, 2, 256);
        GUILayout.Space(3);
        if (GUILayout.Button("骨構造からポリゴンを生成する"))
        {
            CreationSubdivisionJoint(controller, _SubdivisionJointCountH, _SubdivisionJointCountV);
        }
        GUILayout.Space(3);
        _BoneStretchScale = EditorGUILayout.Slider("伸縮比率", _BoneStretchScale, -5.0f, +5.0f);
        if (GUILayout.Button("垂直方向にボーンを伸縮する"))
        {
            controller.StretchBoneLength(_BoneStretchScale);
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemple #5
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();

        colourGradient = serializedObject.FindProperty("lineColour");

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Appearance", EditorStyles.boldLabel);
        lineOptionsInt = GUILayout.Toolbar(lineOptionsInt, lineOptions, EditorStyles.miniButton, GUILayout.Height(18));

        EditorGUILayout.Space();
        pp.noOfTrajectoryPoints = EditorGUILayout.IntField(new GUIContent("No. of Points", "The number of points you want in your trajectory path (more equals smoother path)"), pp.noOfTrajectoryPoints);

        //specific properties for dotted line
        if (lineOptionsInt == 1)
        {
            pp.enableSolidLine = false;

            pp.trajectoryPointPrefab = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Trajectory Prefab", "The prefab you want to clone along your trajectory"), pp.trajectoryPointPrefab, typeof(GameObject), true);
        }

        //specific properties for solid line
        if (lineOptionsInt == 0)
        {
            pp.enableSolidLine = true;
            pp.isAI            = EditorGUILayout.Toggle(new GUIContent("Is AI", "Toggle AI"), pp.isAI);
            pp.cornerVerts     = EditorGUILayout.IntField(new GUIContent("Corner Roundness", "Increase the number of verts at the corners of your trajectory"), pp.cornerVerts);
            pp.endVerts        = EditorGUILayout.IntField(new GUIContent("End Roundness", "Increase roundness of the ends of your trajectory"), pp.endVerts);
            pp.widthCurve      = EditorGUILayout.CurveField(new GUIContent("Width Curve", "Define the width of your trajectory"), pp.widthCurve, Color.red, new Rect(0, 0, 1, 1));
            EditorGUILayout.PropertyField(colourGradient, new GUIContent("Colour", "Define the colour gradient of your trajectory"));

            pp.lineMaterial = (Material)EditorGUILayout.ObjectField(new GUIContent("Material", "Apply a material to your trajectory"), pp.lineMaterial, typeof(Material), true);
            pp.textureMode  = EditorGUILayout.Toggle(new GUIContent("Tiled", "Tile your material along your trajectory"), pp.textureMode == LineTextureMode.Tile) ? LineTextureMode.Tile : LineTextureMode.Stretch;

            if (pp.textureMode == LineTextureMode.Tile)
            {
                EditorGUILayout.HelpBox("Remember to use the Pixul shader located in the Shaders folder", MessageType.Info);
                pp.tileAmount = EditorGUILayout.Slider(new GUIContent("Tile Amount", "Set the tiling amount for your trajectory material"), pp.tileAmount, 0.1f, 10.0f);
            }
        }

        pp.destroyAfterFire = EditorGUILayout.Toggle(new GUIContent("Destroy after firing", "Destroy your trajectory after firing"), pp.destroyAfterFire);
        if (pp.destroyAfterFire)
        {
            pp.destroyDelay = EditorGUILayout.FloatField(new GUIContent("Destroy Delay", "Time to delay the destroy (seconds)"), pp.destroyDelay);
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Physics Properties", EditorStyles.boldLabel);
        pp.m_gravity = EditorGUILayout.Vector2Field(new GUIContent("Gravity", "Controls the effect on the physics object during movement"), pp.m_gravity);
        pp.m_power   = EditorGUILayout.FloatField(new GUIContent("Power", "Factor applied to the initial velocity"), pp.m_power);

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Collision Properties", EditorStyles.boldLabel);
        pp.m_damping = EditorGUILayout.FloatField(new GUIContent("Damping", "Velocity will be factored by this if a collision occurs. Can be overridden using the collision properties script on the colliding object"), pp.m_damping);

        pp.m_ObstaclesLayerMask = EditorGUILayout.LayerField(new GUIContent("Obstacles Layer", "Layer that contains all the objects you wish the physics object to collide with"), pp.m_ObstaclesLayerMask);

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

        // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
Exemple #6
0
    private void OnGUI()
    {
        EditorGUILayout.Space();

        // 测试场景
        SceneAsset scene = (SceneAsset)EditorGUILayout.ObjectField($"测试场景", _profilerScene, typeof(SceneAsset), false);

        if (_profilerScene != scene)
        {
            _profilerScene = scene;
            string path = AssetDatabase.GetAssetPath(scene);
            EditorPrefs.SetString(PROFILER_SCENE_KEY, path);
        }

        // 测试特效
        _effectPrefab = EditorGUILayout.ObjectField($"请选择特效", _effectPrefab, typeof(UnityEngine.Object), false);

        // 测试按钮
        if (GUILayout.Button("测试"))
        {
            if (CheckProfilerCondition() == false)
            {
                return;
            }

            // 焦点锁定游戏窗口
            var          gameViewType = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
            EditorWindow gameView     = EditorWindow.GetWindow(gameViewType);
            gameView.Focus();

            // 开始分析
            _isPause = false;
            _profiler.Analyze(_effectPrefab);
            Debug.Log($"开始测试特效:{_effectPrefab.name}");
        }

        // 暂停按钮
        if (_isPause)
        {
            if (GUILayout.Button("点击按钮恢复"))
            {
                _isPause = false;
            }
        }
        else
        {
            if (GUILayout.Button("点击按钮暂停"))
            {
                _isPause = true;
            }
        }

        // 粒子基本信息
        EditorGUILayout.Space();
        EditorGUILayout.LabelField($"材质数量:{_profiler.MaterialCount}");
        EditorGUILayout.LabelField($"纹理数量:{_profiler.TextureCount}");
        EditorGUILayout.LabelField($"纹理内存:{EditorUtility.FormatBytes(_profiler.TextureMemory)}");
        EditorGUILayout.LabelField($"粒子系统组件:{_profiler.ParticleSystemComponentCount} 个");

        // 粒子动态信息
        EditorGUILayout.Space();
        EditorGUILayout.LabelField($"DrawCall:{_profiler.DrawCallCurrentNum}  最大:{_profiler.DrawCallMaxNum}");
        EditorGUILayout.LabelField($"粒子数量:{_profiler.ParticleCurrentCount}  最大:{_profiler.ParticleMaxCount}");
        EditorGUILayout.LabelField($"三角面数:{_profiler.TriangleCurrentCount}  最大:{_profiler.TriangleMaxCount}");

        // 错误信息
        if (_profiler.Errors.Count > 0)
        {
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox($"请修正以下错误提示", MessageType.Error, true);
            EditorGUI.indentLevel = 1;
            foreach (var error in _profiler.Errors)
            {
                GUIStyle style = new GUIStyle();
                style.normal.textColor = new Color(0.8f, 0, 0);
                EditorGUILayout.LabelField(error, style);
            }
            EditorGUI.indentLevel = 0;
        }

        // 曲线图
        EditorGUILayout.Space();
        using (new EditorGUI.DisabledScope(false))
        {
            _isShowCurves = EditorGUILayout.Foldout(_isShowCurves, "时间曲线");
            if (_isShowCurves)
            {
                float curveHeight = 80;
                EditorGUI.indentLevel = 1;
                EditorGUILayout.LabelField($"采样时长 {_profiler.CurveSampleTime} 秒");
                EditorGUILayout.CurveField("DrawCall", _profiler.DrawCallCurve, GUILayout.Height(curveHeight));
                EditorGUILayout.CurveField("粒子数量", _profiler.ParticleCountCurve, GUILayout.Height(curveHeight));
                EditorGUILayout.CurveField("三角面数", _profiler.TriangleCountCurve, GUILayout.Height(curveHeight));
                EditorGUI.indentLevel = 0;
            }
        }

        // 纹理列表
        EditorGUILayout.Space();
        using (new EditorGUI.DisabledScope(false))
        {
            _isShowTextures = EditorGUILayout.Foldout(_isShowTextures, "纹理列表");
            if (_isShowTextures)
            {
                EditorGUI.indentLevel = 1;
                _scrollPos1           = EditorGUILayout.BeginScrollView(_scrollPos1);
                {
                    List <Texture> textures = _profiler.AllTextures;
                    foreach (var tex in textures)
                    {
                        EditorGUILayout.LabelField($"{tex.name}  尺寸:{tex.height }*{tex.width}  格式:{ParticleProfiler.GetTextureFormatString(tex)}");
                        EditorGUILayout.ObjectField("", tex, typeof(Texture), false, GUILayout.Width(80));
                    }
                }
                EditorGUILayout.EndScrollView();
                EditorGUI.indentLevel = 0;
            }
        }

        // 网格列表
        EditorGUILayout.Space();
        using (new EditorGUI.DisabledScope(false))
        {
            _isShowMeshs = EditorGUILayout.Foldout(_isShowMeshs, "网格列表");
            if (_isShowMeshs)
            {
                EditorGUI.indentLevel = 1;
                _scrollPos2           = EditorGUILayout.BeginScrollView(_scrollPos2);
                {
                    List <Mesh> meshs = _profiler.AllMeshs;
                    foreach (var mesh in meshs)
                    {
                        EditorGUILayout.ObjectField($"三角面数 : {mesh.triangles.Length / 3}", mesh, typeof(MeshFilter), false, GUILayout.Width(300));
                    }
                }
                EditorGUILayout.EndScrollView();
                EditorGUI.indentLevel = 0;
            }
        }

        // 过程化检测结果
        EditorGUILayout.Space();
        using (new EditorGUI.DisabledScope(false))
        {
            _isShowTips = EditorGUILayout.Foldout(_isShowTips, "过程化检测结果");
            if (_isShowTips)
            {
                EditorGUI.indentLevel = 1;
                _scrollPos3           = EditorGUILayout.BeginScrollView(_scrollPos3);
                {
                    GUILayout.Button(_texTips);                     //绘制提示图片
                    EditorGUILayout.HelpBox($"以下粒子系统组件不支持过程化模式!具体原因查看气泡提示", MessageType.Warning, true);
#if UNITY_2018_4_OR_NEWER
                    List <ParticleSystem> particleList = _profiler.AllParticles;
                    foreach (var ps in particleList)
                    {
                        if (ps.proceduralSimulationSupported == false)
                        {
                            EditorGUILayout.ObjectField($"{ps.gameObject.name}", ps.gameObject, typeof(GameObject), false, GUILayout.Width(300));
                        }
                    }
#else
                    EditorGUILayout.LabelField("当前版本不支持过程化检测,请升级至2018.4版本或最新版本");
#endif
                }
                EditorGUILayout.EndScrollView();
                EditorGUI.indentLevel = 0;
            }
        }
    }
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.Space(3);
            EditorGUIUtils.SetGUIStyles();

            bool playMode = Application.isPlaying;

            _runtimeEditMode = _runtimeEditMode && playMode;

            GUILayout.BeginHorizontal();
            EditorGUIUtils.InspectorLogo();
            GUILayout.Label(_src.animationType.ToString() + (string.IsNullOrEmpty(_src.id) ? "" : " [" + _src.id + "]"), EditorGUIUtils.sideLogoIconBoldLabelStyle);
            // Up-down buttons
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("▲", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentUp(_src);
            }
            if (GUILayout.Button("▼", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentDown(_src);
            }
            GUILayout.EndHorizontal();

            if (playMode)
            {
                if (_runtimeEditMode)
                {
                }
                else
                {
                    GUILayout.Space(8);
                    GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
                    if (!_src.isActive)
                    {
                        GUILayout.Label("This animation has been toggled as inactive and won't be generated", EditorGUIUtils.wordWrapLabelStyle);
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button(new GUIContent("Activate Edit Mode", "Switches to Runtime Edit Mode, where you can change animations values and restart them")))
                    {
                        _runtimeEditMode = true;
                    }
                    GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
                    GUILayout.Space(10);
                    if (!_runtimeEditMode)
                    {
                        return;
                    }
                }
            }

            Undo.RecordObject(_src, "DOTween Animation");
            Undo.RecordObject(_settings, "DOTween Animation");

//            _src.isValid = Validate(); // Moved down

            EditorGUIUtility.labelWidth = 110;

            if (playMode)
            {
                GUILayout.Space(4);
                DeGUILayout.Toolbar("Edit Mode Commands");
                DeGUILayout.BeginVBox(DeGUI.styles.box.stickyTop);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("TogglePause"))
                {
                    _src.tween.TogglePause();
                }
                if (GUILayout.Button("Rewind"))
                {
                    _src.tween.Rewind();
                }
                if (GUILayout.Button("Restart"))
                {
                    _src.tween.Restart();
                }
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Commit changes and restart"))
                {
                    _src.tween.Rewind();
                    _src.tween.Kill();
                    if (_src.isValid)
                    {
                        _src.CreateTween();
                        _src.tween.Play();
                    }
                }
                GUILayout.Label("To apply your changes when exiting Play mode, use the Component's upper right menu and choose \"Copy Component\", then \"Paste Component Values\" after exiting Play mode", DeGUI.styles.label.wordwrap);
                DeGUILayout.EndVBox();
            }
            else
            {
                GUILayout.BeginHorizontal();
                bool hasManager = _src.GetComponent <DOTweenVisualManager>() != null;
                EditorGUI.BeginChangeCheck();
                _settings.showPreviewPanel = hasManager
                    ? DeGUILayout.ToggleButton(_settings.showPreviewPanel, "Preview Controls", styles.custom.inlineToggle)
                    : DeGUILayout.ToggleButton(_settings.showPreviewPanel, "Preview Controls", styles.custom.inlineToggle, GUILayout.Width(120));
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(_settings);
                    DOTweenPreviewManager.StopAllPreviews();
                }
                if (!hasManager)
                {
                    if (GUILayout.Button(new GUIContent("Add Manager", "Adds a manager component which allows you to choose additional options for this gameObject")))
                    {
                        _src.gameObject.AddComponent <DOTweenVisualManager>();
                    }
                }
                GUILayout.EndHorizontal();
            }

            // Preview in editor
            bool isPreviewing = _settings.showPreviewPanel ? DOTweenPreviewManager.PreviewGUI(_src) : false;

            EditorGUI.BeginDisabledGroup(isPreviewing);
            // Choose target
            GUILayout.BeginHorizontal();
            _src.isActive = EditorGUILayout.Toggle(new GUIContent("", "If unchecked, this animation will not be created"), _src.isActive, GUILayout.Width(14));
            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginChangeCheck();
            _src.targetIsSelf = DeGUILayout.ToggleButton(
                _src.targetIsSelf, _src.targetIsSelf ? _GuiC_selfTarget_true : _GuiC_selfTarget_false,
                new Color(1f, 0.78f, 0f), DeGUI.colors.bg.toggleOn, new Color(0.33f, 0.14f, 0.02f), DeGUI.colors.content.toggleOn,
                null, GUILayout.Width(47)
                );
            bool innerChanged = EditorGUI.EndChangeCheck();

            if (innerChanged)
            {
                _src.targetGO = null;
                GUI.changed   = true;
            }
            if (_src.targetIsSelf)
            {
                GUILayout.Label(_GuiC_selfTarget_true.tooltip);
            }
            else
            {
                using (new DeGUI.ColorScope(null, null, _src.targetGO == null ? Color.red : Color.white)) {
                    _src.targetGO = (GameObject)EditorGUILayout.ObjectField(_src.targetGO, typeof(GameObject), true);
                }
                _src.tweenTargetIsTargetGO = DeGUILayout.ToggleButton(
                    _src.tweenTargetIsTargetGO, _src.tweenTargetIsTargetGO ? _GuiC_tweenTargetIsTargetGO_true : _GuiC_tweenTargetIsTargetGO_false,
                    GUILayout.Width(131)
                    );
            }
            bool check = EditorGUI.EndChangeCheck();

            if (check)
            {
                _refreshRequired = true;
            }
            GUILayout.EndHorizontal();

            GameObject targetGO = _src.targetIsSelf ? _src.gameObject : _src.targetGO;

            if (targetGO == null)
            {
                // Uses external target gameObject but it's not set
                if (_src.targetGO != null || _src.target != null)
                {
                    _src.targetGO = null;
                    _src.target   = null;
                    GUI.changed   = true;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                DOTweenAnimation.AnimationType prevAnimType = _src.animationType;
//                _src.animationType = (DOTweenAnimation.AnimationType)EditorGUILayout.EnumPopup(_src.animationType, EditorGUIUtils.popupButton);
                GUI.enabled        = GUI.enabled && _src.isActive;
                _src.animationType = AnimationToDOTweenAnimationType(_AnimationType[EditorGUILayout.Popup(DOTweenAnimationTypeToPopupId(_src.animationType), _AnimationType)]);
                _src.autoPlay      = DeGUILayout.ToggleButton(_src.autoPlay, new GUIContent("AutoPlay", "If selected, the tween will play automatically"));
                _src.autoKill      = DeGUILayout.ToggleButton(_src.autoKill, new GUIContent("AutoKill", "If selected, the tween will be killed when it completes, and won't be reusable"));
                GUILayout.EndHorizontal();
                if (prevAnimType != _src.animationType)
                {
                    // Set default optional values based on animation type
                    _src.endValueTransform = null;
                    _src.useTargetAsV3     = false;
                    switch (_src.animationType)
                    {
                    case DOTweenAnimation.AnimationType.Move:
                    case DOTweenAnimation.AnimationType.LocalMove:
                    case DOTweenAnimation.AnimationType.Rotate:
                    case DOTweenAnimation.AnimationType.LocalRotate:
                    case DOTweenAnimation.AnimationType.Scale:
                        _src.endValueV3    = Vector3.zero;
                        _src.endValueFloat = 0;
                        _src.optionalBool0 = _src.animationType == DOTweenAnimation.AnimationType.Scale;
                        break;

                    case DOTweenAnimation.AnimationType.UIWidthHeight:
                        _src.endValueV3    = Vector3.zero;
                        _src.endValueFloat = 0;
                        _src.optionalBool0 = _src.animationType == DOTweenAnimation.AnimationType.UIWidthHeight;
                        break;

                    case DOTweenAnimation.AnimationType.Color:
                    case DOTweenAnimation.AnimationType.Fade:
                        _isLightSrc        = targetGO.GetComponent <Light>() != null;
                        _src.endValueFloat = 0;
                        break;

                    case DOTweenAnimation.AnimationType.Text:
                        _src.optionalBool0 = true;
                        break;

                    case DOTweenAnimation.AnimationType.PunchPosition:
                    case DOTweenAnimation.AnimationType.PunchRotation:
                    case DOTweenAnimation.AnimationType.PunchScale:
                        _src.endValueV3     = _src.animationType == DOTweenAnimation.AnimationType.PunchRotation ? new Vector3(0, 180, 0) : Vector3.one;
                        _src.optionalFloat0 = 1;
                        _src.optionalInt0   = 10;
                        _src.optionalBool0  = false;
                        break;

                    case DOTweenAnimation.AnimationType.ShakePosition:
                    case DOTweenAnimation.AnimationType.ShakeRotation:
                    case DOTweenAnimation.AnimationType.ShakeScale:
                        _src.endValueV3     = _src.animationType == DOTweenAnimation.AnimationType.ShakeRotation ? new Vector3(90, 90, 90) : Vector3.one;
                        _src.optionalInt0   = 10;
                        _src.optionalFloat0 = 90;
                        _src.optionalBool0  = false;
                        break;

                    case DOTweenAnimation.AnimationType.CameraAspect:
                    case DOTweenAnimation.AnimationType.CameraFieldOfView:
                    case DOTweenAnimation.AnimationType.CameraOrthoSize:
                        _src.endValueFloat = 0;
                        break;

                    case DOTweenAnimation.AnimationType.CameraPixelRect:
                    case DOTweenAnimation.AnimationType.CameraRect:
                        _src.endValueRect = new Rect(0, 0, 0, 0);
                        break;
                    }
                }
                if (_src.animationType == DOTweenAnimation.AnimationType.None)
                {
                    _src.isValid = false;
                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(_src);
                    }
                    return;
                }

                if (_refreshRequired || prevAnimType != _src.animationType || ComponentsChanged())
                {
                    _refreshRequired = false;
                    _src.isValid     = Validate(targetGO);
                    // See if we need to choose between multiple targets
#if true // UI_MARKER
                    if (_src.animationType == DOTweenAnimation.AnimationType.Fade && targetGO.GetComponent <CanvasGroup>() != null && targetGO.GetComponent <Image>() != null)
                    {
                        _chooseTargetMode = ChooseTargetMode.BetweenCanvasGroupAndImage;
                        // Reassign target and forcedTargetType if lost
                        if (_src.forcedTargetType == DOTweenAnimation.TargetType.Unset)
                        {
                            _src.forcedTargetType = _src.targetType;
                        }
                        switch (_src.forcedTargetType)
                        {
                        case DOTweenAnimation.TargetType.CanvasGroup:
                            _src.target = targetGO.GetComponent <CanvasGroup>();
                            break;

                        case DOTweenAnimation.TargetType.Image:
                            _src.target = targetGO.GetComponent <Image>();
                            break;
                        }
                    }
                    else
                    {
#endif
                    _chooseTargetMode     = ChooseTargetMode.None;
                    _src.forcedTargetType = DOTweenAnimation.TargetType.Unset;
#if true // UI_MARKER
                }
#endif
                }

                if (!_src.isValid)
                {
                    GUI.color = Color.red;
                    GUILayout.BeginVertical(GUI.skin.box);
                    GUILayout.Label("No valid Component was found for the selected animation", EditorGUIUtils.wordWrapLabelStyle);
                    GUILayout.EndVertical();
                    GUI.color = Color.white;
                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(_src);
                    }
                    return;
                }

#if true // UI_MARKER
                // Special cases in which multiple target types could be used (set after validation)
                if (_chooseTargetMode == ChooseTargetMode.BetweenCanvasGroupAndImage && _src.forcedTargetType != DOTweenAnimation.TargetType.Unset)
                {
                    FadeTargetType fadeTargetType = (FadeTargetType)Enum.Parse(typeof(FadeTargetType), _src.forcedTargetType.ToString());
                    DOTweenAnimation.TargetType prevTargetType = _src.forcedTargetType;
                    _src.forcedTargetType = (DOTweenAnimation.TargetType)Enum.Parse(typeof(DOTweenAnimation.TargetType), EditorGUILayout.EnumPopup(_src.animationType + " Target", fadeTargetType).ToString());
                    if (_src.forcedTargetType != prevTargetType)
                    {
                        // Target type change > assign correct target
                        switch (_src.forcedTargetType)
                        {
                        case DOTweenAnimation.TargetType.CanvasGroup:
                            _src.target = targetGO.GetComponent <CanvasGroup>();
                            break;

                        case DOTweenAnimation.TargetType.Image:
                            _src.target = targetGO.GetComponent <Image>();
                            break;
                        }
                    }
                }
#endif

                GUILayout.BeginHorizontal();
                _src.duration = EditorGUILayout.FloatField("Duration", _src.duration);
                if (_src.duration < 0)
                {
                    _src.duration = 0;
                }
                _src.isSpeedBased = DeGUILayout.ToggleButton(_src.isSpeedBased, new GUIContent("SpeedBased", "If selected, the duration will count as units/degree x second"), DeGUI.styles.button.tool, GUILayout.Width(75));
                GUILayout.EndHorizontal();
                _src.delay = EditorGUILayout.FloatField("Delay", _src.delay);
                if (_src.delay < 0)
                {
                    _src.delay = 0;
                }
                _src.isIndependentUpdate = EditorGUILayout.Toggle("Ignore TimeScale", _src.isIndependentUpdate);
                _src.easeType            = EditorGUIUtils.FilteredEasePopup(_src.easeType);
                if (_src.easeType == Ease.INTERNAL_Custom)
                {
                    _src.easeCurve = EditorGUILayout.CurveField("   Ease Curve", _src.easeCurve);
                }
                _src.loops = EditorGUILayout.IntField(new GUIContent("Loops", "Set to -1 for infinite loops"), _src.loops);
                if (_src.loops < -1)
                {
                    _src.loops = -1;
                }
                if (_src.loops > 1 || _src.loops == -1)
                {
                    _src.loopType = (LoopType)EditorGUILayout.EnumPopup("   Loop Type", _src.loopType);
                }
                _src.id = EditorGUILayout.TextField("ID", _src.id);

                bool canBeRelative = true;
                // End value and eventual specific options
                switch (_src.animationType)
                {
                case DOTweenAnimation.AnimationType.Move:
                case DOTweenAnimation.AnimationType.LocalMove:
                    GUIEndValueV3(targetGO, _src.animationType == DOTweenAnimation.AnimationType.Move);
                    _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    canBeRelative      = !_src.useTargetAsV3;
                    break;

                case DOTweenAnimation.AnimationType.Rotate:
                case DOTweenAnimation.AnimationType.LocalRotate:
                    bool isRigidbody2D = DOTweenModuleUtils.Physics.HasRigidbody2D(_src);
                    if (isRigidbody2D)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV3(targetGO);
                        _src.optionalRotationMode = (RotateMode)EditorGUILayout.EnumPopup("    Rotation Mode", _src.optionalRotationMode);
                    }
                    break;

                case DOTweenAnimation.AnimationType.Scale:
                    if (_src.optionalBool0)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV3(targetGO);
                    }
                    _src.optionalBool0 = EditorGUILayout.Toggle("Uniform Scale", _src.optionalBool0);
                    break;

                case DOTweenAnimation.AnimationType.UIWidthHeight:
                    if (_src.optionalBool0)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV2();
                    }
                    _src.optionalBool0 = EditorGUILayout.Toggle("Uniform Scale", _src.optionalBool0);
                    break;

                case DOTweenAnimation.AnimationType.Color:
                    GUIEndValueColor();
                    canBeRelative = false;
                    break;

                case DOTweenAnimation.AnimationType.Fade:
                    GUIEndValueFloat();
                    if (_src.endValueFloat < 0)
                    {
                        _src.endValueFloat = 0;
                    }
                    if (!_isLightSrc && _src.endValueFloat > 1)
                    {
                        _src.endValueFloat = 1;
                    }
                    canBeRelative = false;
                    break;

                case DOTweenAnimation.AnimationType.Text:
                    GUIEndValueString();
                    _src.optionalBool0        = EditorGUILayout.Toggle("Rich Text Enabled", _src.optionalBool0);
                    _src.optionalScrambleMode = (ScrambleMode)EditorGUILayout.EnumPopup("Scramble Mode", _src.optionalScrambleMode);
                    _src.optionalString       = EditorGUILayout.TextField(new GUIContent("Custom Scramble", "Custom characters to use in case of ScrambleMode.Custom"), _src.optionalString);
                    break;

                case DOTweenAnimation.AnimationType.PunchPosition:
                case DOTweenAnimation.AnimationType.PunchRotation:
                case DOTweenAnimation.AnimationType.PunchScale:
                    GUIEndValueV3(targetGO);
                    canBeRelative       = false;
                    _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the punch vibrate"), _src.optionalInt0, 1, 50);
                    _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Elasticity", "How much the vector will go beyond the starting position when bouncing backwards"), _src.optionalFloat0, 0, 1);
                    if (_src.animationType == DOTweenAnimation.AnimationType.PunchPosition)
                    {
                        _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    }
                    break;

                case DOTweenAnimation.AnimationType.ShakePosition:
                case DOTweenAnimation.AnimationType.ShakeRotation:
                case DOTweenAnimation.AnimationType.ShakeScale:
                    GUIEndValueV3(targetGO);
                    canBeRelative       = false;
                    _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the shake vibrate"), _src.optionalInt0, 1, 50);
                    _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Randomness", "The shake randomness"), _src.optionalFloat0, 0, 90);
                    if (_src.animationType == DOTweenAnimation.AnimationType.ShakePosition)
                    {
                        _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    }
                    break;

                case DOTweenAnimation.AnimationType.CameraAspect:
                case DOTweenAnimation.AnimationType.CameraFieldOfView:
                case DOTweenAnimation.AnimationType.CameraOrthoSize:
                    GUIEndValueFloat();
                    canBeRelative = false;
                    break;

                case DOTweenAnimation.AnimationType.CameraBackgroundColor:
                    GUIEndValueColor();
                    canBeRelative = false;
                    break;

                case DOTweenAnimation.AnimationType.CameraPixelRect:
                case DOTweenAnimation.AnimationType.CameraRect:
                    GUIEndValueRect();
                    canBeRelative = false;
                    break;
                }

                // Final settings
                if (canBeRelative)
                {
                    _src.isRelative = EditorGUILayout.Toggle("    Relative", _src.isRelative);
                }

                // Events
                AnimationInspectorGUI.AnimationEvents(this, _src);
            }
            EditorGUI.EndDisabledGroup();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_src);
            }
        }
        //...
        public static object DirectFieldControl(GUIContent content, object value, Type t, UnityEngine.Object unityObjectContext, object[] attributes, out bool handled, params GUILayoutOption[] options)
        {
            handled = true;

            //Check scene object type for UnityObjects. Consider Interfaces as scene object type. Assume that user uses interfaces with UnityObjects
            if (typeof(UnityObject).IsAssignableFrom(t) || t.IsInterface)
            {
                var isSceneObjectType = (typeof(Component).IsAssignableFrom(t) || t == typeof(GameObject) || t.IsInterface);
                if (value == null || value is UnityObject)     //check this to avoid case of interface but no unityobject
                {
                    var newValue = EditorGUILayout.ObjectField(content, (UnityObject)value, t, isSceneObjectType, options);
                    if (unityObjectContext != null && newValue != null)
                    {
                        if (!Application.isPlaying && EditorUtility.IsPersistent(unityObjectContext) && !EditorUtility.IsPersistent(newValue as UnityEngine.Object))
                        {
                            ParadoxNotion.Services.Logger.LogWarning("Assets can not have scene object references", "Editor", unityObjectContext);
                            newValue = value as UnityObject;
                        }
                    }
                    return(newValue);
                }
            }

            //Check Type second
            if (t == typeof(Type))
            {
                return(Popup <Type>(content, (Type)value, TypePrefs.GetPreferedTypesList(true), options));
            }

            //get real current type
            t = value != null?value.GetType() : t;

            //for these just show type information
            if (t.IsAbstract || t == typeof(object) || typeof(Delegate).IsAssignableFrom(t) || typeof(UnityEngine.Events.UnityEventBase).IsAssignableFrom(t))
            {
                EditorGUILayout.LabelField(content, new GUIContent(string.Format("({0})", t.FriendlyName())), options);
                return(value);
            }

            //create instance for value types
            if (value == null && t.RTIsValueType())
            {
                value = System.Activator.CreateInstance(t);
            }

            //create new instance with button for non value types
            if (value == null && !t.IsAbstract && !t.IsInterface && (t.IsArray || t.GetConstructor(Type.EmptyTypes) != null))
            {
                if (content != GUIContent.none)
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(content, GUI.skin.button);
                }
                if (GUILayout.Button("(null) Create", options))
                {
                    value = t.IsArray ? Array.CreateInstance(t.GetElementType(), 0) : Activator.CreateInstance(t);
                }
                if (content != GUIContent.none)
                {
                    GUILayout.EndHorizontal();
                }
                return(value);
            }


            ///----------------------------------------------------------------------------------------------


            if (t == typeof(string))
            {
                return(EditorGUILayout.TextField(content, (string)value, options));
            }

            if (t == typeof(char))
            {
                var c = (char)value;
                var s = c.ToString();
                s = EditorGUILayout.TextField(content, s, options);
                return(string.IsNullOrEmpty(s) ? (char)c : (char)s[0]);
            }

            if (t == typeof(bool))
            {
                return(EditorGUILayout.Toggle(content, (bool)value, options));
            }

            if (t == typeof(int))
            {
                return(EditorGUILayout.IntField(content, (int)value, options));
            }

            if (t == typeof(float))
            {
                return(EditorGUILayout.FloatField(content, (float)value, options));
            }

            if (t == typeof(byte))
            {
                return(Convert.ToByte(Mathf.Clamp(EditorGUILayout.IntField(content, (byte)value, options), 0, 255)));
            }

            if (t == typeof(long))
            {
                return(EditorGUILayout.LongField(content, (long)value, options));
            }

            if (t == typeof(double))
            {
                return(EditorGUILayout.DoubleField(content, (double)value, options));
            }

            if (t == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(content, (Vector2)value, options));
            }

            if (t == typeof(Vector2Int))
            {
                return(EditorGUILayout.Vector2IntField(content, (Vector2Int)value, options));
            }

            if (t == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(content, (Vector3)value, options));
            }

            if (t == typeof(Vector3Int))
            {
                return(EditorGUILayout.Vector3IntField(content, (Vector3Int)value, options));
            }

            if (t == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(content, (Vector4)value, options));
            }

            if (t == typeof(Quaternion))
            {
                var quat = (Quaternion)value;
                var vec4 = new Vector4(quat.x, quat.y, quat.z, quat.w);
                vec4 = EditorGUILayout.Vector4Field(content, vec4, options);
                return(new Quaternion(vec4.x, vec4.y, vec4.z, vec4.w));
            }

            if (t == typeof(Color))
            {
                var att       = attributes?.FirstOrDefault(a => a is ColorUsageAttribute) as ColorUsageAttribute;
                var hdr       = att != null? att.hdr : false;
                var showAlpha = att != null? att.showAlpha : true;
                return(EditorGUILayout.ColorField(content, (Color)value, true, showAlpha, hdr, options));
            }

            if (t == typeof(Gradient))
            {
                return(EditorGUILayout.GradientField(content, (Gradient)value, options));
            }

            if (t == typeof(Rect))
            {
                return(EditorGUILayout.RectField(content, (Rect)value, options));
            }

            if (t == typeof(AnimationCurve))
            {
                return(EditorGUILayout.CurveField(content, (AnimationCurve)value, options));
            }

            if (t == typeof(Bounds))
            {
                return(EditorGUILayout.BoundsField(content, (Bounds)value, options));
            }

            if (t == typeof(LayerMask))
            {
                return(LayerMaskField(content, (LayerMask)value, options));
            }

            if (t.IsSubclassOf(typeof(System.Enum)))
            {
                if (t.RTIsDefined(typeof(FlagsAttribute), true))
                {
#if UNITY_2017_3_OR_NEWER
                    return(EditorGUILayout.EnumFlagsField(content, (System.Enum)value, options));
#else
                    return(EditorGUILayout.EnumMaskPopup(content, (System.Enum)value, options));
#endif
                }
                return(EditorGUILayout.EnumPopup(content, (System.Enum)value, options));
            }

            handled = false;
            return(value);
        }
        /// <summary>
        /// Custom Inspector drawing for DS_HazeCore components.
        /// </summary>
        public override void OnInspectorGUI()
        {
            // Make the foldout text bold.
            GUIStyle foldoutStyle     = new GUIStyle(EditorStyles.foldout);
            GUIStyle headerLabelStyle = new GUIStyle(EditorStyles.boldLabel);

            headerLabelStyle.alignment = TextAnchor.MiddleLeft;

            // Get the styles for the mini buttons and 'solo' toggle.
            GUIStyle variantStyle = new GUIStyle(EditorStyles.helpBox);

            variantStyle.padding = new RectOffset(0, 2, 3, 3);
            GUIStyle buttonLeft       = GUI.skin.FindStyle("ButtonLeft");
            GUIStyle buttonRight      = GUI.skin.FindStyle("ButtonRight");
            GUIStyle miniButtonStyleL = new GUIStyle(EditorStyles.miniButtonLeft);
            GUIStyle miniButtonStyleM = new GUIStyle(EditorStyles.miniButtonMid);
            GUIStyle miniButtonStyleR = new GUIStyle(EditorStyles.miniButtonRight);

            // Style for expandable help text.
            GUIStyle helpBoxStyle = new GUIStyle(EditorStyles.helpBox);

            helpBoxStyle.richText = true;
            Texture2D helpIconImage = EditorGUIUtility.FindTexture("console.infoicon.sml");
            GUIStyle  helpIconStyle = new GUIStyle();

            helpIconStyle.normal.background    = helpIconImage;
            helpIconStyle.onNormal.background  = helpIconImage;
            helpIconStyle.active.background    = helpIconImage;
            helpIconStyle.onActive.background  = helpIconImage;
            helpIconStyle.focused.background   = helpIconImage;
            helpIconStyle.onFocused.background = helpIconImage;

            serializedObject.Update();
            DS_HazeZone        hazeZone      = target as DS_HazeZone;
            SerializedProperty soloIndexProp = m_ContextProp.FindPropertyRelative("m_SoloItem");

            // Handle the object picker for selecting a preset. Note that the actual loading happens at the end of
            // this function and only after a Repaint event.
            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Zone Parameters:", headerLabelStyle);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Priority"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BlendRange"));

                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Create Preset", buttonLeft))
                    {
                        PopupWindow.Show(m_SavePresetRect, m_PresetNamePopup);
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        m_SavePresetRect = GUILayoutUtility.GetLastRect();
                    }

                    if (GUILayout.Button("Load Preset", buttonRight))
                    {
                        int ctrlID = EditorGUIUtility.GetControlID(FocusType.Passive);
                        EditorGUIUtility.ShowObjectPicker <DS_HazeContextAsset>(null, false, "", ctrlID);
                    }
                    m_HelpTxtExpanded = EditorGUILayout.Toggle(m_HelpTxtExpanded, helpIconStyle, GUILayout.Width(helpIconImage.width));
                }
                EditorGUILayout.EndHorizontal();
                if (m_HelpTxtExpanded)
                {
                    EditorGUILayout.TextArea(kHelpTxt, helpBoxStyle);
                }


                // Check for messages returned by the object picker.
                if (Event.current.commandName == "ObjectSelectorClosed")
                {
                    m_WaitingToLoad = EditorGUIUtility.GetObjectPickerObject() as DS_HazeContextAsset;
                }
                EditorGUILayout.Space();

                // Manually calculate a scaling factor based on the current width of the Inspector and a fixed minimum width.
                float maxLabelWidth = EditorGUIUtility.labelWidth;
                if (EditorGUIUtility.currentViewWidth < 350)
                {
                    maxLabelWidth = Mathf.Lerp(50, EditorGUIUtility.labelWidth, (1.0f / (350.0f - 275.0f)) * (EditorGUIUtility.currentViewWidth - 275.0f));
                }

                EditorGUILayout.LabelField("Time-Of-Day Variants:", EditorStyles.boldLabel);
                SerializedProperty ctxVariants = m_ContextProp.FindPropertyRelative("m_ContextItems");
                for (int cv = 0; cv < ctxVariants.arraySize; cv++)
                {
                    SerializedProperty cvElem       = ctxVariants.GetArrayElementAtIndex(cv);
                    SerializedProperty cvName       = cvElem.FindPropertyRelative("m_Name");
                    SerializedProperty cvWeightProp = cvElem.FindPropertyRelative("m_Weight");

                    Rect cvRect = EditorGUILayout.BeginHorizontal(variantStyle);
                    {
                        cvRect.y    += 5;
                        cvRect.width = 50;

                        // Draw the foldout and get the expanded state of this variant.
                        cvElem.isExpanded = EditorGUI.Foldout(cvRect, cvElem.isExpanded, GUIContent.none, true, foldoutStyle);
                        EditorGUILayout.LabelField(cvName.stringValue, headerLabelStyle, GUILayout.Width(maxLabelWidth));

                        // Draw the 'solo' button.
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.Toggle(cv == soloIndexProp.intValue, GUILayout.Width(12));
                        if (EditorGUI.EndChangeCheck())
                        {
                            soloIndexProp.intValue = soloIndexProp.intValue != cv ? cv : -1;
                        }

                        // Draw the weight curve as part of the header, so we can edit the weighting without having to expand the whole context.
                        cvWeightProp.animationCurveValue = EditorGUILayout.CurveField(cvWeightProp.animationCurveValue, Color.green, new Rect(0, 0, 1, 1));

                        // Add, move up/down and delete buttons.
                        if (GUILayout.Button("+", miniButtonStyleL))
                        {
                            hazeZone.Context.DuplicateContextItem(cv);
                        }
                        if (GUILayout.Button('\u25B2'.ToString(), miniButtonStyleM))
                        {
                            hazeZone.Context.MoveContextItemUp(cv);
                        }
                        if (GUILayout.Button('\u25BC'.ToString(), miniButtonStyleM))
                        {
                            hazeZone.Context.MoveContextItemDown(cv);
                        }
                        if (GUILayout.Button("-", miniButtonStyleR))
                        {
                            hazeZone.Context.RemoveContextItem(cv);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    // If the context variant is expanded, draw its actual property below the header.
                    if (cvElem.isExpanded)
                    {
                        EditorGUILayout.PropertyField(cvElem);
                    }
                }
            }
            EditorGUILayout.EndVertical();
            serializedObject.ApplyModifiedProperties();

            // Check if there's a context waiting to be loaded. We need to wait until
            // after a repaint event as it will probably modify the size of the context variants
            // list. This can cause a mis-match between what was setup during the Layout event and
            // what we're now drawing during a Repaint.
            if (Event.current.type == EventType.Repaint && m_WaitingToLoad != null)
            {
                LoadFromContextPreset(m_WaitingToLoad);
                m_WaitingToLoad = null;
            }
        }
Exemple #10
0
    /// <summary>
    /// 绘制窗口
    /// </summary>
    public void OnGUI()
    {
        if (GUILayout.Button("关闭"))
        {//关闭按钮
            Close();
        }
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("显示通知"))
        {
            GUIContent content = new GUIContent();
            content.text    = "通知";
            content.tooltip = "ShowNotification";
            ShowNotification(new GUIContent(content));
        }
        if (GUILayout.Button("关闭通知"))
        {
            RemoveNotification();
        }
        EditorGUILayout.EndHorizontal();

        //滚动视图分组↓
        scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos);

        //Label
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("文本");
        EditorGUILayout.SelectableLabel("可选文本");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        //水平分组↓
        EditorGUILayout.BeginHorizontal();
        //数值输入
        intField   = EditorGUILayout.IntField("整数", intField);
        floatField = EditorGUILayout.FloatField("浮点数", floatField);
        EditorGUILayout.EndHorizontal();
        //水平分组↑

        EditorGUILayout.Space();

        //文本输入
        EditorGUILayout.BeginHorizontal();
        textField     = EditorGUILayout.TextField("文本输入框", textField);
        passwordField = EditorGUILayout.PasswordField("密码输入框", passwordField);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("可换行的文本输入框");
        textArea = EditorGUILayout.TextArea(textArea);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        //颜色
        colorField = EditorGUILayout.ColorField("取色器", colorField);

        EditorGUILayout.Space();

        //垂直分组
        EditorGUILayout.BeginVertical();
        //滑动条
        sliderVal = EditorGUILayout.Slider("浮点数滚动条", sliderVal, 0, 1);
        intSlider = EditorGUILayout.IntSlider("整数滚动条", intSlider, 0, 10);
        EditorGUILayout.MinMaxSlider("区间滚动条", ref v2MinMax.x, ref v2MinMax.y, 0, 1);
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();

        //多元数
        vector2Field = EditorGUILayout.Vector2Field("二维向量", vector2Field);
        vector3Field = EditorGUILayout.Vector3Field("三维向量", vector3Field);
        vector4Field = EditorGUILayout.Vector4Field("四维向量", vector4Field);
        rectField    = EditorGUILayout.RectField("矩形", rectField);
        boundsField  = EditorGUILayout.BoundsField("边界", boundsField);

        EditorGUILayout.Space();

        //下拉列表
        popupVal     = EditorGUILayout.Popup("返回选项数组下标", popupVal, new string[] { "A", "B" });
        intPopupVal  = EditorGUILayout.IntPopup("返回选项数组下标对应的整数数组值", intPopupVal, new string[] { "A", "B" }, new int[] { 1, 2 });
        enumPopupVal = (Condition)EditorGUILayout.EnumPopup("返回枚举", enumPopupVal);

        EditorGUILayout.Space();

        //
        tagField   = EditorGUILayout.TagField("TagField", tagField);
        layerField = EditorGUILayout.LayerField("LayerField", layerField);

        EditorGUILayout.Space();

        foldout = EditorGUILayout.Foldout(foldout, "折叠");
        if (foldout)
        {
            EditorGUILayout.LabelField("折叠内容1");
            EditorGUILayout.LabelField("折叠内容2");
        }

        EditorGUILayout.Space();

        toggle = EditorGUILayout.Toggle("复选框", toggle);

        EditorGUILayout.Space();

        //启用/禁用分组中的内容
        toggleGroup = EditorGUILayout.BeginToggleGroup("启用/禁用分组中的内容", toggleGroup);
        EditorGUILayout.TextField("sdk");
        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.Space();

        curveField        = EditorGUILayout.CurveField("动画片段", curveField);
        inspectorTitlebar = EditorGUILayout.InspectorTitlebar(inspectorTitlebar, objectField);    //将选择的物体放在面板上
        objectField       = EditorGUILayout.ObjectField("ObjectField", objectField, typeof(RectTransform), true);

        EditorGUILayout.EndScrollView();
        //滚动视图分组↑

        #region Mask
        //_enumValue0 = (EnumValue0)EditorGUILayout.EnumMaskField("EnumMaskField", _enumValue0);
        //EditorGUILayout.EnumMaskPopup();
        _enumCustom = (EnumCustom)EditorGUILayout.EnumFlagsField(_enumCustom);
        #endregion
    }
Exemple #11
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector(); // initialize Inspector
        //EditorGUILayout.LabelField(serializedObject.FindProperty("loopAnimation").stringValue);
        miniLabelStyle.wordWrap = true;
        matGateController matGate = (matGateController)target; // attach matGateController

        //loopAnimation = matGateController.loopAnimation;

        // Various Button:
        GUILayout.Space(6);
        EditorGUILayout.LabelField("General Controls", EditorStyles.boldLabel);
        GUILayout.Label("General options for modification to the texture.");
        EditorGUILayout.BeginVertical("Box");
        GUILayout.Label("These functions are to be used in scene mode. They will be saved for game mode. Change values above and click Update. You can save at anytime.", miniLabelStyle);
        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical("Box");
        if (GUILayout.Button("Update")) // Updates the texture with the changed values in edit mode
        {
            matGate.pushGate();
        }
        if (GUILayout.Button("Randomize Small")) // randomizes to a small degree
        {
            matGate.pushGate_randomSmall();
        }
        if (GUILayout.Button("Randomize Large")) // randomizes to a larger degree
        {
            matGate.pushGate_random();
        }
        if (GUILayout.Button("Randomize Pixel")) // randomly pixellates the entire texture
        {
            matGate.pushGate_randomPixel();
        }
        if (GUILayout.Button("Loop Animation")) // randomly pixellates the entire texture
        {
            if (loopAnimation == false)
            {
                loopAnimation = true;
            }
            else
            {
                loopAnimation = false;
            }
            Repaint();
        }
        if (GUILayout.Button("Save")) // save the texture with the save named entered as the string
        {
            matGate.pushGate_save(saveName);
        }

        saveName = GUILayout.TextField(saveName, 25); // max filename length is 25 characters

        EditorGUILayout.EndVertical();
        GUILayout.Space(3);

        //mode7:
        #region Drawing Mode7Config fields and updating the config
        GUILayout.Space(6);
        EditorGUILayout.LabelField("Animation Controls", EditorStyles.boldLabel);
        GUILayout.Label("Animation options for recording modification to the texture.");
        EditorGUILayout.BeginVertical("Box");
        GUILayout.Label("Enter values for x, y, and others. Click '+' to add more states. Change your colors for the grid to your liking. This works in scene and game modes.", miniLabelStyle);
        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical("Box");
        col1        = EditorGUILayout.ColorField("Odd row color", col1);
        col2        = EditorGUILayout.ColorField("Even row color", col2);
        colSelected = EditorGUILayout.ColorField("Selected row color", colSelected);

        matGate.animationCurve = EditorGUILayout.CurveField("Animation Curve", matGate.animationCurve, Color.green, new Rect(0, 0, 1, 1), GUILayout.Height(100));
        matGate.animationTime  = Mathf.Max(EditorGUILayout.DelayedFloatField("Animation time", matGate.animationTime), 0);

        float buttonWidth  = 25;
        float fieldWidth   = 40;
        float configHeight = 10;
        float spacing      = 5;

        GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField)
        {
            alignment = TextAnchor.MiddleCenter
        };

        GUIStyle richTextButtonStyle = new GUIStyle(GUI.skin.button)
        {
            richText = true
        };

        GUIStyle middleAlignedText = new GUIStyle(EditorStyles.label)
        {
            alignment = TextAnchor.MiddleCenter,
            richText  = true
        };

        Rect     r      = GUILayoutUtility.GetRect(buttonWidth, configHeight + spacing);
        string[] labels = new string[] { "H", "V", "X<size=7>0</size>", "Y<size=7>0</size>", "A", "B", "C", "D" };

        for (int i = 0; i < labels.Length; i++)
        {
            Rect labelRect = new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * i, r.y, fieldWidth, r.height);
            EditorGUI.DrawRect(labelRect, Color.grey);
            EditorGUI.LabelField(labelRect, labels[i], middleAlignedText);
        }

        if (GUI.Button(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 8, r.y, 30, r.height), "+", richTextButtonStyle))
        {
            matGate.configs.Insert(0, new Mode7Config());
            selectedIndex++;
        }

        for (int i = 0; i < matGate.configs.Count; i++)
        {
            r = GUILayoutUtility.GetRect(buttonWidth, configHeight + spacing);

            EditorGUI.DrawRect(new Rect(r.x, r.y, r.width, r.height), i == selectedIndex ? colSelected : (((i & 1) > 0) ? col1 : col2));

            string buttonText;

            if (i != selectedIndex)
            {
                buttonText = i.ToString();
            }
            else
            {
                buttonText = "<color=" + (isAnimating ? "red" : "black") + "><b>" + i.ToString() + "</b></color>";
            }

            if (GUI.Button(new Rect(r.x, r.y, buttonWidth, r.height), buttonText, richTextButtonStyle))
            {
                selectedIndex = i;
                //Debug.LogFormat("Animation start at {0}", Time.time);
                isAnimating = true;
                matGate.animationStartTime = Time.time;
                startConfig  = matGate.GetConfig();
                targetConfig = matGate.configs[i];
            }


            Mode7Config config = matGate.configs[i];
            config.h  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 0, r.y, fieldWidth, r.height), config.h, numberFieldStyle);
            config.v  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 1, r.y, fieldWidth, r.height), config.v, numberFieldStyle);
            config.x0 = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 2, r.y, fieldWidth, r.height), config.x0, numberFieldStyle);
            config.y0 = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 3, r.y, fieldWidth, r.height), config.y0, numberFieldStyle);
            config.a  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 4, r.y, fieldWidth, r.height), config.a, numberFieldStyle);
            config.b  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 5, r.y, fieldWidth, r.height), config.b, numberFieldStyle);
            config.c  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 6, r.y, fieldWidth, r.height), config.c, numberFieldStyle);
            config.d  = EditorGUI.FloatField(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 7, r.y, fieldWidth, r.height), config.d, numberFieldStyle);
            if (config != matGate.configs[i])
            {
                //Debug.Log("Value updated");
                matGate.configs[i] = config;
                if (i == selectedIndex)
                {
                    UpdateConfig(matGate);
                }
            }
            #endregion

            if (GUI.Button(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 8, r.y, 30, r.height), "+", richTextButtonStyle))
            {
                matGate.configs.Insert(i + 1, new Mode7Config());
                if (selectedIndex > i)
                {
                    selectedIndex++;
                }
            }

            if (GUI.Button(new Rect(buttonWidth + 20 + spacing + (spacing + fieldWidth) * 8 + 30 + spacing, r.y, 30, r.height), "-", richTextButtonStyle))
            {
                matGate.configs.RemoveAt(i);
                selectedIndex = Mathf.Max(0, selectedIndex - 1);
                UpdateConfig(matGate);
            }
        }

        if (isAnimating)
        {
            if (matGate.animationStartTime + matGate.animationTime < Time.deltaTime)
            {
                //Debug.Log("Animation end");

                isAnimating = false;
            }
            else
            {
                Mode7Config config = matGate.InterpolateFromTo(startConfig, targetConfig, (Time.time - matGate.animationStartTime) / matGate.animationTime);
                matGate.SetConfig(config);
            }
            Repaint();
        }
    }