Наследование: MonoBehaviour
Пример #1
0
    private void decorate(SplineDecorator decorator)
    {
        float frequency = decorator.frequency;

        Transform[] items = decorator.items;

        foreach (Transform t in decorated)
        {
            DestroyImmediate(t.gameObject);
        }
        decorated.Clear();

        if (frequency <= 0 || items == null || items.Length == 0)
        {
            return;
        }
        float stepSize = 1f / (frequency * items.Length);

        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < items.Length; i++, p++)
            {
                Transform item     = Instantiate(items[i]) as Transform;
                Vector3   position = decorator.spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (decorator.lookForward)
                {
                    item.transform.LookAt(position + decorator.spline.GetDirection(p * stepSize));
                }
                item.transform.parent = decorator.spline.transform;
                Undo.RegisterCreatedObjectUndo(item.gameObject, "Decorate");
                decorated.Add(item);
            }
        }
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        SplineDecorator decorator = target as SplineDecorator;

        if (GUILayout.Button("Decorate"))
        {
            decorate(decorator);
        }
    }
Пример #3
0
    public override void OnInspectorGUI()
    {
        SplineDecorator deco = target as SplineDecorator;

        deco.spline = deco.GetComponent <BezierSpline>();

        if (GUILayout.Button("Fill Spline"))
        {
            Undo.RecordObject(deco, "Revert Fill");
            deco.Decorate();
            EditorUtility.SetDirty(deco);
        }
    }
Пример #4
0
 public override void OnInspectorGUI()
 {
     splineDecorator = target as SplineDecorator;
     DrawDefaultInspector();
     if (GUILayout.Button("Update"))
     {
         Undo.RecordObject(splineDecorator, "Update");
         splineDecorator.UpdateDecoration();
         EditorUtility.SetDirty(splineDecorator);
     }
     if (GUILayout.Button("Clear"))
     {
         Undo.RecordObject(splineDecorator, "Clear");
         splineDecorator.ForceClearDecoration();
         EditorUtility.SetDirty(splineDecorator);
     }
 }
Пример #5
0
    //triggered once the vertext points of the spline decorator have been created
    public void createMesh()
    {
        if (enabled)
        {
            if (model == null)
            {
                model = new Mesh();
            }


            spD             = GetComponent <SplineDecorator>();
            counter         = 0;
            Inputpoints     = spD.getPointList();
            nodesPerSegment = Inputpoints.Count / spD.frequency;
            if (capped)
            {
                tris = new int[((((nodesPerSegment * 2) * 3))
                                * (spD.frequency - 1)) + (((nodesPerSegment - 2) * 3) * 2)];
            }
            else
            {
                tris = new int[((((nodesPerSegment * 2) * 3)) * (spD.frequency - 1))];
            }

            pointLocs = new Vector3[Inputpoints.Count];
            foreach (GameObject go in Inputpoints)
            {
                pointLocs[counter++] = go.transform.position;
            }

            counter = 0;
            for (int i = 0; i < spD.frequency - 1; i++)
            {
                calcTris(nodesPerSegment * i);
            }
            if (capped)
            {
                calcEndCaps();
            }
            model.vertices = pointLocs;

            model.triangles = tris;
            MeshHolder.gameObject.GetComponent <Renderer>().material = _inMat;
            model.RecalculateNormals();
        }
    }
 public override void OnInspectorGUI()
 {
     EditorStyles.label.wordWrap         = true;
     splineDecorator                     = target as SplineDecorator;
     splineDecorator.spline              = (BezierSpline)EditorGUILayout.ObjectField("Bezier Spline", splineDecorator.spline, typeof(BezierSpline), true);
     splineDecorator.radius              = EditorGUILayout.FloatField("Wire Radius", splineDecorator.radius);
     splineDecorator.cVertCount          = EditorGUILayout.IntField("Circ. Vertex Count", splineDecorator.cVertCount);
     splineDecorator.cVertCount          = (splineDecorator.cVertCount < 3) ? 3 : splineDecorator.cVertCount;
     splineDecorator.loopCount           = EditorGUILayout.IntField("Loop Count", splineDecorator.loopCount);
     splineDecorator.loopCount           = (splineDecorator.loopCount < 1) ? 1 : splineDecorator.loopCount;
     splineDecorator.decorationFrequency = EditorGUILayout.IntField("Decoration Freq.", splineDecorator.decorationFrequency);
     splineDecorator.decoration          = (Transform)EditorGUILayout.ObjectField("Decoration", splineDecorator.decoration, typeof(Transform), true);
     splineDecorator.hook                = (Transform)EditorGUILayout.ObjectField("Hook", splineDecorator.hook, typeof(Transform), true);
     if (splineDecorator.spline == null)
     {
         GUI.enabled = false;
     }
     if (meshExists)
     {
         if (GUILayout.Button("Regenerate Mesh"))
         {
             //update vertices and decoration placements
             //update everything if any of the details have been changed
             splineDecorator.GenerateMesh();
         }
     }
     else
     {
         if (GUILayout.Button("GenerateMesh"))
         {
             meshExists = true;
             splineDecorator.GenerateMesh();
         }
     }
     if (splineDecorator.spline == null)
     {
         GUI.enabled = true;
         EditorGUILayout.LabelField("Cannot generate or update mesh without Bezier Spline");
     }
 }
    private bool testPoints()
    {
        SplineDecorator SPD = GetComponent <SplineDecorator>();

        if (splineRelatedControlPoints == null)
        {
            collatePoints();
        }


        for (int i = 0; i < splineRelatedControlPoints.Count; i++)
        {
            if (SPD.controlPoints[i].gameObject.transform.position
                != splineRelatedControlPoints[i].transform.position)
            {
                splineRelatedControlPoints[i].transform.position
                    = GetComponent <SplineDecorator>().controlPoints[i].transform.position;
                print("Returning true");
                return(true);
            }
        }
        return(false);
    }
Пример #8
0
 // Use this for initialization
 void Start()
 {
     scripts = GetComponents <FetherTool>();
     spd     = GetComponent <SplineDecorator>();
 }