Exemple #1
0
    public void Init()
    {
        track = gameObject.AddComponent <TrackBuildRTrack>();
        track.InitTextures();
        track.baseTransform = transform;

        TrackBuildRPoint p0 = gameObject.AddComponent <TrackBuildRPoint>(); // ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p1 = gameObject.AddComponent <TrackBuildRPoint>(); //ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p2 = gameObject.AddComponent <TrackBuildRPoint>(); //ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p3 = gameObject.AddComponent <TrackBuildRPoint>(); //ScriptableObject.CreateInstance<TrackBuildRPoint>();

        p0.baseTransform = transform;
        p1.baseTransform = transform;
        p2.baseTransform = transform;
        p3.baseTransform = transform;

        p0.position = new Vector3(-20, 0, -20);
        p1.position = new Vector3(20, 0, -20);
        p2.position = new Vector3(20, 0, 20);
        p3.position = new Vector3(-20, 0, 20);

        p0.forwardControlPoint = new Vector3(0, 0, -20);
        p1.forwardControlPoint = new Vector3(40, 0, -20);
        p2.forwardControlPoint = new Vector3(0, 0, 20);
        p3.forwardControlPoint = new Vector3(-40, 0, 20);

        p0.leftForwardControlPoint = new Vector3(-15, 0, -20);
        p1.leftForwardControlPoint = new Vector3(25, 0, -20);
        p2.leftForwardControlPoint = new Vector3(5, 0, 20);
        p3.leftForwardControlPoint = new Vector3(-35, 0, 20);

        p0.rightForwardControlPoint = new Vector3(15, 0, -20);
        p1.rightForwardControlPoint = new Vector3(55, 0, -20);
        p2.rightForwardControlPoint = new Vector3(-5, 0, 20);
        p3.rightForwardControlPoint = new Vector3(-45, 0, 20);

        track.AddPoint(p0);
        track.AddPoint(p1);
        track.AddPoint(p2);
        track.AddPoint(p3);

        generator = gameObject.AddComponent <TrackBuildRGenerator>();

        ForceFullRecalculation();

        track.diagramMesh           = new Mesh();
        track.diagramMesh.vertices  = new [] { new Vector3(-1, 0, -1), new Vector3(1, 0, -1), new Vector3(-1, 0, 1), new Vector3(1, 0, 1) };
        track.diagramMesh.uv        = new [] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1) };
        track.diagramMesh.triangles = new [] { 1, 0, 2, 1, 2, 3 };

        track.diagramGO = new GameObject("Diagram");
        track.diagramGO.transform.parent                 = transform;
        track.diagramGO.transform.localPosition          = Vector3.zero;
        track.diagramGO.AddComponent <MeshFilter>().mesh = track.diagramMesh;
        track.diagramMaterial = new Material(Shader.Find("Unlit/Texture"));
        track.diagramGO.AddComponent <MeshRenderer>().material   = track.diagramMaterial;
        track.diagramGO.AddComponent <MeshCollider>().sharedMesh = track.diagramMesh;
    }
Exemple #2
0
    public void Init()
    {
        track = gameObject.AddComponent<TrackBuildRTrack>();
        track.InitTextures();
        track.baseTransform = transform;

        TrackBuildRPoint p0 = gameObject.AddComponent<TrackBuildRPoint>();// ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p1 = gameObject.AddComponent<TrackBuildRPoint>();//ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p2 = gameObject.AddComponent<TrackBuildRPoint>();//ScriptableObject.CreateInstance<TrackBuildRPoint>();
        TrackBuildRPoint p3 = gameObject.AddComponent<TrackBuildRPoint>();//ScriptableObject.CreateInstance<TrackBuildRPoint>();

        p0.baseTransform = transform;
        p1.baseTransform = transform;
        p2.baseTransform = transform;
        p3.baseTransform = transform;

        p0.position = new Vector3(-20, 0, -20);
        p1.position = new Vector3(20, 0, -20);
        p2.position = new Vector3(20, 0, 20);
        p3.position = new Vector3(-20, 0, 20);

        p0.forwardControlPoint = new Vector3(0, 0, -20);
        p1.forwardControlPoint = new Vector3(40, 0, -20);
        p2.forwardControlPoint = new Vector3(0, 0, 20);
        p3.forwardControlPoint = new Vector3(-40, 0, 20);

        p0.leftForwardControlPoint = new Vector3(-15, 0, -20);
        p1.leftForwardControlPoint = new Vector3(25, 0, -20);
        p2.leftForwardControlPoint = new Vector3(5, 0, 20);
        p3.leftForwardControlPoint = new Vector3(-35, 0, 20);

        p0.rightForwardControlPoint = new Vector3(15, 0, -20);
        p1.rightForwardControlPoint = new Vector3(55, 0, -20);
        p2.rightForwardControlPoint = new Vector3(-5, 0, 20);
        p3.rightForwardControlPoint = new Vector3(-45, 0, 20);

        track.AddPoint(p0);
        track.AddPoint(p1);
        track.AddPoint(p2);
        track.AddPoint(p3);

        generator = gameObject.AddComponent<TrackBuildRGenerator>();

        ForceFullRecalculation();

        track.diagramMesh = new Mesh();
        track.diagramMesh.vertices = new [] { new Vector3(-1, 0, -1), new Vector3(1, 0, -1), new Vector3(-1, 0, 1), new Vector3(1, 0, 1)};
        track.diagramMesh.uv = new [] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0,1), new Vector2(1,1)};
        track.diagramMesh.triangles = new []{1,0,2,1,2,3};

        track.diagramGO = new GameObject("Diagram");
        track.diagramGO.transform.parent = transform;
        track.diagramGO.transform.localPosition = Vector3.zero;
        track.diagramGO.AddComponent<MeshFilter>().mesh = track.diagramMesh;
        track.diagramMaterial = new Material(Shader.Find("Unlit/Texture"));
        track.diagramGO.AddComponent<MeshRenderer>().material = track.diagramMaterial;
        track.diagramGO.AddComponent<MeshCollider>().sharedMesh = track.diagramMesh;
    }