Esempio n. 1
0
    IEnumerator startSpawning()
    {
        if (parentGO == null)
        {
            parentGO = new GameObject("GeneratedObjects");
        }

        for (int i = 0; i < numberOfObjects; i++)
        {
            Vector3 spawnPosition = transform.position;
            float   rnd           = Random.Range(-rndFactor, rndFactor);
            spawnPosition.z += rnd;
            spawnPosition.x += rnd;

            GameObject go = Instantiate(prefab, spawnPosition, Quaternion.identity) as GameObject;
            go.transform.position = spawnPosition;
            CubeAtlasUVManager cm = go.GetComponent <CubeAtlasUVManager>();
            if (cm == null)
            {
                throw new System.Exception("Prefab must have CubeAtlasUVManager on it");
            }
            cm.randomizeFaces(10);
            go.transform.parent = parentGO.transform;
            yield return(new WaitForSeconds(timeout));
        }
    }
Esempio n. 2
0
    void OnEnable()
    {
        CubeAtlasUVManager cm = (CubeAtlasUVManager)target;

        UVPositions.Add("front", cm.front);
        UVPositions.Add("back", cm.back);
        UVPositions.Add("left", cm.left);
        UVPositions.Add("right", cm.right);
        UVPositions.Add("top", cm.top);
        UVPositions.Add("bottom", cm.bottom);


        createMeshIfNull();
    }
Esempio n. 3
0
    private Mesh  instantiateMesh()
    {
        CubeAtlasUVManager cam        = (CubeAtlasUVManager)target;
        GameObject         gameObject = cam.gameObject;
        MeshFilter         mf         = gameObject.GetComponent <MeshFilter>();
        Mesh sharedMesh = mf.sharedMesh;

        if (sharedMesh != null)
        {
            Mesh m = cloneMesh(sharedMesh);
            mf.sharedMesh = m;
            return(m);
        }
        return(sharedMesh);
    }
Esempio n. 4
0
    void createMeshIfNull()
    {
        CubeAtlasUVManager cm = (CubeAtlasUVManager)target;

        if (cm.gameObject.GetComponent <MeshFilter>().sharedMesh == null)
        {
            GameObject cube    = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Mesh       newMesh = cloneMesh(cube.GetComponent <MeshFilter>().sharedMesh);
            cm.gameObject.GetComponent <MeshFilter>().sharedMesh = newMesh;

            DestroyImmediate(cube);

            AssetDatabase.CreateAsset(newMesh, AssetDatabase.GetAssetPath(target).Replace("prefab", "mesh.asset"));
            AssetDatabase.SaveAssets();
        }
    }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        CubeAtlasUVManager cm = (CubeAtlasUVManager)target;

        int numberOfTiles = cm.rowCount * cm.columnCount - 1;

        if (GUILayout.Button("Instantiate Shared Mesh"))
        {
            instantiateMesh();
        }


        int newRowCountIntValue = EditorGUILayout.IntField("Row Count", cm.rowCount);

        if (newRowCountIntValue != cm.rowCount)
        {
            cm.rowCount = newRowCountIntValue;
            updateTargetMesh();
        }

        int newColumnCountIntValue = EditorGUILayout.IntField("Column Count", cm.columnCount);

        if (newColumnCountIntValue != cm.columnCount)
        {
            cm.columnCount = newColumnCountIntValue;
            updateTargetMesh();
        }

        foreach (KeyValuePair <string, UVPosition> uvPosition in UVPositions)
        {
            EditorGUILayout.LabelField("--------------------------------------------------------------");
            EditorGUILayout.PrefixLabel(uvPosition.Key);
            int newPosition = EditorGUILayout.IntSlider("position", uvPosition.Value.position, 0, numberOfTiles);
            if (newPosition != uvPosition.Value.position)
            {
                uvPosition.Value.position = newPosition;
                updateTargetMesh();
            }

            int newRotation = EditorGUILayout.IntSlider("rotation", uvPosition.Value.rotation, 0, 3);
            if (newRotation != uvPosition.Value.rotation)
            {
                uvPosition.Value.rotation = newRotation;
                updateTargetMesh();
            }
        }
    }
Esempio n. 6
0
    void updateTargetMesh()
    {
        CubeAtlasUVManager cm = (CubeAtlasUVManager)target;

        cm.updateMesh();
    }