示例#1
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = GetTarget() as MeshDeformer;
            }

            if (m_meshDeformer == null)
            {
                return;
            }


            int curveIndex = (SelectedIndex - 1) / 3;

            GUILayout.BeginHorizontal();
            {
                if (curveIndex == m_meshDeformer.CurveCount - 1)
                {
                    if (GUILayout.Button("Append"))
                    {
                        Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Append");
                        Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(), "Battlehub.MeshDeformer.Append");
                        EditorUtility.SetDirty(m_meshDeformer);
                        Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
                    }
                }

                if (curveIndex == 0)
                {
                    if (GUILayout.Button("Prepend"))
                    {
                        Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                        RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                        Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
                        EditorUtility.SetDirty(m_meshDeformer);
                        Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Straighten"))
            {
                Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                EditorUtility.SetDirty(m_meshDeformer);
                m_meshDeformer.Straighten(SelectedIndex);
            }

            if (SelectedIndex >= 0 && curveIndex < m_meshDeformer.CurveCount)
            {
                if (GUILayout.Button("Remove"))
                {
                    Remove();
                }
            }
        }
示例#2
0
 // Use this for initialization
 void Start()
 {
     
     MeshDeformer deformer = gameObject.AddComponent<MeshDeformer>();
     deformer.Axis = Axis.Y;
     deformer.ResetDeformer();
     deformer.Extend();
     deformer.Extend();
     deformer.CurvesPerMesh = 2;
     deformer.Spacing = 1;
     deformer.Approximation = 50;
     deformer.SetControlPointLocal(0, new Vector3(-1, -4, -1));
 }
示例#3
0
        public static void Append()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Append");
            Undo.RegisterCreatedObjectUndo(deformer.Extend(), "Battlehub.MeshDeformer.Append");
            EditorUtility.SetDirty(deformer);
            Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
        }
示例#4
0
 public override void Append()
 {
     if (SplineRuntimeEditor.Instance != null)
     {
         MeshDeformer deformer = SplineRuntimeEditor.Instance.SelectedSpline as MeshDeformer;
         if (deformer != null)
         {
             deformer.Extend();
         }
         else
         {
             base.Append();
         }
     }
 }
示例#5
0
        public static void Prepend()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Prepend");
            Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
            foreach (Scaffold scaffold in scaffolds)
            {
                Undo.RecordObject(scaffold, "Battlehub.MeshDeformer.Prepend");
            }
            Undo.RegisterCreatedObjectUndo(deformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
            EditorUtility.SetDirty(deformer);
            Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
        }
示例#6
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_deformer == null)
            {
                m_deformer = GetTarget() as MeshDeformer;
            }

            if (m_deformer == null)
            {
                return;
            }

            DoOriginalMeshes();

            EditorGUI.BeginChangeCheck();
            Axis axis = (Axis)EditorGUILayout.EnumPopup("Deformation Axis", m_deformer.Axis);

            if (EditorGUI.EndChangeCheck())
            {
                ChangeAxis(m_deformer, axis);
            }

            EditorGUI.BeginChangeCheck();
            int sliceCount = EditorGUILayout.IntField("Approximation", m_deformer.Approximation);

            if (EditorGUI.EndChangeCheck())
            {
                if (sliceCount > 100)
                {
                    if (!EditorUtility.DisplayDialog("Are you sure", "Are you sure you want to set Approximation = " + sliceCount, "Yes", "No"))
                    {
                        sliceCount = m_deformer.Approximation;
                    }
                }
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                EditorUtility.SetDirty(m_deformer);

                Debug.Log("Undo Operations will be Collapsed");
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());

                m_deformer.Approximation = sliceCount;
            }

            EditorGUI.BeginChangeCheck();
            float spacing = EditorGUILayout.FloatField("Spacing", m_deformer.Spacing);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Spacing Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Spacing Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Spacing = spacing;
            }

            EditorGUI.BeginChangeCheck();
            int curvesPerMesh = EditorGUILayout.IntField("Curves Per Mesh", m_deformer.CurvesPerMesh);

            if (EditorGUI.EndChangeCheck())
            {
                Selection.activeGameObject = m_deformer.gameObject;
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.CurvesPerMesh Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.CurvesPerMesh Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.CurvesPerMesh = curvesPerMesh;
            }

            EditorGUI.BeginChangeCheck();
            bool loop = EditorGUILayout.Toggle("Loop", m_deformer.Loop);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, UNDO_TOGGLELOOP);
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Loop = loop;
            }


            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Append"))
                {
                    Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Append");
                    Undo.RegisterCreatedObjectUndo(m_deformer.Extend(), "Battlehub.MeshDeformer.Append");
                    EditorUtility.SetDirty(m_deformer);
                    //Selection.activeGameObject = m_deformer.GetComponentsInChildren<ControlPoint>().Last().gameObject;
                }

                if (GUILayout.Button("Prepend"))
                {
                    Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Prepend");
                    RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Prepend");
                    Undo.RegisterCreatedObjectUndo(m_deformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
                    EditorUtility.SetDirty(m_deformer);
                    //Selection.activeGameObject = m_deformer.GetComponentsInChildren<ControlPoint>().First().gameObject;
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Smooth Spline"))
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Fit");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Fit");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Smooth();
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
                {
                    if (GUILayout.Button("Set Rigid Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, true);
                    }

                    if (GUILayout.Button("Set Free Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
                {
                    if (GUILayout.Button("Set Aligned Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                        SetMode(m_deformer, ControlPointMode.Aligned, false);
                    }

                    if (GUILayout.Button("Set Mirrored Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                        SetMode(m_deformer, ControlPointMode.Mirrored, false);
                    }
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();



#if MD_GIZMOS
            EditorGUI.BeginChangeCheck();
            bool drawGizoms = EditorGUILayout.Toggle("Draw Gizmos", m_deformer.DrawGizmos);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.DrawGizmos = drawGizoms;
            }
#endif
        }
示例#7
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = (MeshDeformer)GetTarget();
            }

            if (m_meshDeformer == null)
            {
                return;
            }

            Scaffold        scaffold        = (Scaffold)target;
            ScaffoldWrapper scaffoldWrapper = null;
            int             scaffoldIndex   = -1;

            for (int i = 0; i < m_meshDeformer.Scaffolds.Length; ++i)
            {
                if (scaffold == m_meshDeformer.Scaffolds[i].Obj)
                {
                    scaffoldIndex   = i;
                    scaffoldWrapper = m_meshDeformer.Scaffolds[i];
                    break;
                }
            }

            if (scaffoldWrapper != null)
            {
                EditorGUI.BeginChangeCheck();
                bool isRigid = EditorGUILayout.Toggle("Is Rigid", scaffoldWrapper.IsRigid);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_meshDeformer, UNDO_CHANGEMODE);
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                    EditorUtility.SetDirty(m_meshDeformer);

                    for (int i = 0; i < scaffoldWrapper.CurveIndices.Length; ++i)
                    {
                        int curveIndex = scaffoldWrapper.CurveIndices[i];
                        m_meshDeformer.SetIsRigid(curveIndex * 3, isRigid);
                    }
                }
            }

            if (scaffold.gameObject != m_meshDeformer.gameObject)
            {
                GUILayout.BeginHorizontal();
                {
                    if (scaffoldIndex == m_meshDeformer.Scaffolds.Length - 1)
                    {
                        if (GUILayout.Button("Append"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Append");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(), "Battlehub.MeshDeformer.Append");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
                        }
                    }

                    if (scaffoldIndex == 0)
                    {
                        if (GUILayout.Button("Prepend"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }

            if (scaffoldWrapper != null)
            {
                if (GUILayout.Button("Straighten"))
                {
                    Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    EditorUtility.SetDirty(m_meshDeformer);
                    m_meshDeformer.Straighten(scaffoldWrapper.CurveIndices.Min() * 3 + 1);
                }
            }
        }