コード例 #1
0
        protected virtual void HeaderGUI()
        {
            SplineUser user = (SplineUser)target;

            Undo.RecordObject(user, "Inspector Change");
            SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue;

            EditorGUILayout.PropertyField(spline);
            SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue;

            if (lastSpline != (SplineComputer)spline.objectReferenceValue)
            {
                for (int i = 0; i < users.Length; i++)
                {
                    if (lastSpline != null)
                    {
                        lastSpline.Unsubscribe(users[i]);
                    }
                    if (newSpline != null)
                    {
                        newSpline.Subscribe(users[i]);
                    }
                }
                user.Rebuild();
            }


            if (user.spline == null)
            {
                EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error);
            }

            settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "User Configuration", foldoutHeaderStyle);
            if (settingsFoldout)
            {
                EditorGUI.indentLevel++;
                if (showClip)
                {
                    InspectorClipEdit();
                }
                if (showUpdateMethod)
                {
                    EditorGUILayout.PropertyField(updateMethodProperty);
                }
                EditorGUILayout.PropertyField(autoUpdateProperty, new GUIContent("Auto Rebuild"));
                if (showMultithreading)
                {
                    EditorGUILayout.PropertyField(multithreadedProperty);
                }
                EditorGUILayout.PropertyField(buildOnAwakeProperty);
                EditorGUILayout.PropertyField(buildOnEnableProperty);
                EditorGUI.indentLevel--;
            }
        }
コード例 #2
0
 void Bake()
 {
     meshGen.Bake(isStatic, true);
     if (permanent && !copy)
     {
         SplineComputer meshGenComputer = meshGen.spline;
         if (permanent)
         {
             meshGenComputer.Unsubscribe(meshGen);
             DestroyImmediate(meshGen);
         }
         if (removeComputer)
         {
             if (meshGenComputer.GetComponents <Component>().Length == 2)
             {
                 DestroyImmediate(meshGenComputer.gameObject);
             }
             else
             {
                 DestroyImmediate(meshGenComputer);
             }
         }
     }
 }
コード例 #3
0
        private void Bake(MeshGenerator gen)
        {
            MeshFilter filter = gen.GetComponent <MeshFilter>();

            if (filter == null)
            {
                EditorUtility.DisplayDialog("Save error", "No mesh present in " + gen.name, "OK");
                return;
            }
            if (copy)
            {
                UnityEditor.MeshUtility.Optimize(filter.sharedMesh);
                Unwrapping.GenerateSecondaryUVSet(filter.sharedMesh);
            }
            else
            {
                gen.Bake(isStatic, true);
            }

            if (format == BakeMeshWindow.SaveFormat.OBJ)
            {
                MeshRenderer renderer = gen.GetComponent <MeshRenderer>();
                dirInfo = new DirectoryInfo(savePath);
                FileInfo[] files    = dirInfo.GetFiles(filter.sharedMesh.name + "*.obj");
                string     meshName = filter.sharedMesh.name;
                if (files.Length > 0)
                {
                    meshName += "_" + files.Length;
                }
                string path      = savePath + "/" + meshName + ".obj";
                string objString = Dreamteck.MeshUtility.ToOBJString(filter.sharedMesh, renderer.sharedMaterials);
                File.WriteAllText(path, objString);
                if (copy)
                {
                    string relativepath = "Assets" + path.Substring(Application.dataPath.Length);
                    AssetDatabase.ImportAsset(relativepath, ImportAssetOptions.ForceSynchronousImport);
                    filter.sharedMesh = AssetDatabase.LoadAssetAtPath <Mesh>(relativepath);
                }
            }

            if (format == BakeMeshWindow.SaveFormat.MeshAsset)
            {
                dirInfo = new DirectoryInfo(savePath);
                FileInfo[] files    = dirInfo.GetFiles(filter.sharedMesh.name + "*.asset");
                string     meshName = filter.sharedMesh.name;
                if (files.Length > 0)
                {
                    meshName += "_" + files.Length;
                }
                string path         = savePath + "/" + meshName + ".asset";
                string relativepath = "Assets" + path.Substring(Application.dataPath.Length);
                if (copy)
                {
                    Mesh assetMesh = Dreamteck.MeshUtility.Copy(filter.sharedMesh);
                    AssetDatabase.CreateAsset(assetMesh, relativepath);
                }
                else
                {
                    AssetDatabase.CreateAsset(filter.sharedMesh, relativepath);
                }
            }

            if (permanent && !copy)
            {
                SplineComputer meshGenComputer = gen.spline;
                if (permanent)
                {
                    meshGenComputer.Unsubscribe(gen);
                    Object.DestroyImmediate(gen);
                }
                if (removeComputer)
                {
                    if (meshGenComputer.GetComponents <Component>().Length == 2)
                    {
                        Object.DestroyImmediate(meshGenComputer.gameObject);
                    }
                    else
                    {
                        Object.DestroyImmediate(meshGenComputer);
                    }
                }
            }
        }
コード例 #4
0
        protected virtual void HeaderGUI()
        {
            SplineUser user = (SplineUser)target;

            bool isClosed    = true;
            bool loopSamples = true;

            for (int i = 0; i < users.Length; i++)
            {
                if (users[i].spline == null)
                {
                    isClosed = false;
                }
                else if (!users[i].spline.isClosed)
                {
                    isClosed = false;
                }
                else if (!users[i].loopSamples)
                {
                    loopSamples = false;
                }
            }

            Undo.RecordObject(user, "Inspector Change");
            SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue;

            EditorGUILayout.PropertyField(spline);
            SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue;

            if (lastSpline != (SplineComputer)spline.objectReferenceValue)
            {
                for (int i = 0; i < users.Length; i++)
                {
                    if (lastSpline != null)
                    {
                        lastSpline.Unsubscribe(users[i]);
                    }
                    if (newSpline != null)
                    {
                        newSpline.Subscribe(users[i]);
                    }
                }
                user.Rebuild();
            }

            //if (GUI.changed) serializedObject.ApplyModifiedProperties();


            if (user.spline == null)
            {
                EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error);
            }

            if (showClip)
            {
                float clipFrom = 0f, clipTo = 1f;
                clipFrom = this.clipFrom.floatValue;
                clipTo   = this.clipTo.floatValue;
                float lastFrom = clipFrom, lastTo = clipTo;
                EditorGUI.BeginChangeCheck();

                if (isClosed && loopSamples)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (EditButton(_editIndex == 0))
                    {
                        if (_editIndex == 0)
                        {
                            _editIndex = -1;
                        }
                        else
                        {
                            _editIndex = 0;
                        }
                    }
                    EditorGUILayout.BeginVertical();
                    clipFrom = EditorGUILayout.Slider("Clip From", clipFrom, 0f, 1f);
                    clipTo   = EditorGUILayout.Slider("Clip To", clipTo, 0f, 1f);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    if (EditButton(_editIndex == 0))
                    {
                        if (_editIndex == 0)
                        {
                            _editIndex = -1;
                        }
                        else
                        {
                            _editIndex = 0;
                        }
                    }
                    EditorGUIUtility.labelWidth = 80f;
                    EditorGUILayout.MinMaxSlider(new GUIContent("Clip Range:"), ref clipFrom, ref clipTo, 0f, 1f);
                    EditorGUIUtility.labelWidth = 0f;
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(30));
                    clipFrom = EditorGUILayout.FloatField(clipFrom);
                    clipTo   = EditorGUILayout.FloatField(clipTo);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndHorizontal();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    this.clipFrom.floatValue = clipFrom;
                    this.clipTo.floatValue   = clipTo;
                }
                SplineComputerEditor.hold = _editIndex >= 0;

                if (isClosed)
                {
                    EditorGUILayout.PropertyField(this.loopSamples, new GUIContent("Loop Samples"));
                }
                if (!this.loopSamples.boolValue || !isClosed)
                {
                    if (this.clipFrom.floatValue > this.clipTo.floatValue)
                    {
                        float temp = this.clipTo.floatValue;
                        this.clipTo.floatValue   = this.clipFrom.floatValue;
                        this.clipFrom.floatValue = temp;
                    }
                }
            }

            settings = EditorGUILayout.Foldout(settings, "Settings");
            if (settings)
            {
                EditorGUI.indentLevel++;
                if (showUpdateMethod)
                {
                    EditorGUILayout.PropertyField(updateMethod);
                }
                EditorGUILayout.PropertyField(autoUpdate, new GUIContent("Auto Rebuild"));
                if (showMultithreading)
                {
                    EditorGUILayout.PropertyField(multithreaded);
                }
                EditorGUILayout.PropertyField(buildOnAwake);
                EditorGUILayout.PropertyField(buildOnEnable);
                EditorGUI.indentLevel--;
            }
        }
コード例 #5
0
        void Merge(int index, MergeSide mergingSide)
        {
            RecordUndo("Merge Splines");
            SplineComputer mergedSpline = availableMergeComputers[index];

            SplinePoint[]      mergedPoints = mergedSpline.GetPoints();
            SplinePoint[]      original     = spline.GetPoints();
            List <SplinePoint> pointsList   = new List <SplinePoint>();

            SplinePoint[] points;
            if (!mergeEndpoints)
            {
                points = new SplinePoint[mergedPoints.Length + original.Length];
            }
            else
            {
                points = new SplinePoint[mergedPoints.Length + original.Length - 1];
            }

            if (mergeSide == MergeSide.End)
            {
                if (mergingSide == MergeSide.Start)
                {
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                    for (int i = mergeEndpoints ? 1 : 0; i < mergedPoints.Length; i++)
                    {
                        pointsList.Add(mergedPoints[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                    for (int i = 0; i < mergedPoints.Length - (mergeEndpoints ? 1 : 0); i++)
                    {
                        pointsList.Add(mergedPoints[(mergedPoints.Length - 1) - i]);
                    }
                }
            }
            else
            {
                if (mergingSide == MergeSide.Start)
                {
                    for (int i = 0; i < mergedPoints.Length - (mergeEndpoints ? 1 : 0); i++)
                    {
                        pointsList.Add(mergedPoints[(mergedPoints.Length - 1) - i]);
                    }
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                }
                else
                {
                    for (int i = mergeEndpoints ? 1 : 0; i < mergedPoints.Length; i++)
                    {
                        pointsList.Add(mergedPoints[i]);
                    }
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                }
            }
            points = pointsList.ToArray();
            double mergedPercent = (double)(mergedPoints.Length - 1) / (points.Length - 1);
            double from          = 0.0;
            double to            = 1.0;

            if (mergeSide == MergeSide.End)
            {
                from = 1.0 - mergedPercent;
                to   = 1.0;
            }
            else
            {
                from = 0.0;
                to   = mergedPercent;
            }


            List <Node> mergedNodes   = new List <Node>();
            List <int>  mergedIndices = new List <int>();

            for (int i = 0; i < mergedSpline.pointCount; i++)
            {
                Node node = mergedSpline.GetNode(i);
                if (node != null)
                {
                    mergedNodes.Add(node);
                    mergedIndices.Add(i);
                    Undo.RecordObject(node, "Disconnect Node");
                    mergedSpline.DisconnectNode(i);
                    i--;
                }
            }

            SplineUser[] subs = mergedSpline.GetSubscribers();
            for (int i = 0; i < subs.Length; i++)
            {
                mergedSpline.Unsubscribe(subs[i]);
                subs[i].spline   = spline;
                subs[i].clipFrom = DMath.Lerp(from, to, subs[i].clipFrom);
                subs[i].clipTo   = DMath.Lerp(from, to, subs[i].clipTo);
            }
            spline.SetPoints(points);

            if (mergeSide == MergeSide.Start)
            {
                spline.ShiftNodes(0, spline.pointCount - 1, mergedSpline.pointCount);
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    spline.ConnectNode(mergedNodes[i], mergedIndices[i]);
                }
            }
            else
            {
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    int connectIndex = mergedIndices[i] + original.Length;
                    if (mergeEndpoints)
                    {
                        connectIndex--;
                    }
                    spline.ConnectNode(mergedNodes[i], connectIndex);
                }
            }
            if (EditorUtility.DisplayDialog("Keep merged computer's GameObject?", "Do you want to keep the merged computer's game object?", "Yes", "No"))
            {
                Undo.DestroyObjectImmediate(mergedSpline);
            }
            else
            {
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    if (TransformUtility.IsParent(mergedNodes[i].transform, mergedSpline.transform))
                    {
                        Undo.SetTransformParent(mergedNodes[i].transform, mergedSpline.transform.parent, "Reparent Node");
                    }
                }
                Undo.DestroyObjectImmediate(mergedSpline.gameObject);
            }

            FindAvailableComputers();
        }