Пример #1
0
 public override void Init(PCGResources res)
 {
     mr = GetComponent <MeshRenderer>();
     if (allMats.Count <= 0)
     {
         enabled = false;
         return;
     }
     mr.enabled = true;
     UpdateSettings();
 }
Пример #2
0
        public override void Init(PCGResources res)
        {
            allMatrices = new NativeList <float4x4>(20, Allocator.Persistent);
            tileOffsets = new NativeList <float4>(20, Allocator.Persistent);
            if (!mesh || targetMats.Count <= 0)
            {
                enabled = false;
                return;
            }
            NativeArray <MeshAppdata> meshData;

            int[] tri;
            int   vertLen = PCGLibrary.GetAppDataFromMesh(mesh, out meshData, out tri);

            meshBuffer = new ComputeBuffer(vertLen, sizeof(MeshAppdata));
            meshBuffer.SetData(meshData);
            instanceBuffer = new ComputeBuffer(20, sizeof(PerObjectDatas));
            triangleBuffer = new ComputeBuffer(tri.Length, sizeof(int));
            triangleBuffer.SetData(tri);
        }
Пример #3
0
 public abstract void Init(PCGResources resources);
Пример #4
0
 public override void Init(PCGResources resources)
 {
 }
Пример #5
0
        private void OnGUI()
        {
            if (!PCGMain.current)
            {
                GameObject pcgMain = new GameObject("PCG Main", typeof(PCGMain));
                PCGMain.current = pcgMain.GetComponent <PCGMain>();
            }
            res = PCGMain.current.pcgRes;
            if (!res)
            {
                EditorGUILayout.LabelField("PCG Resource is NULL!");
                return;
            }
            if (!PCGMain.current.enabled)
            {
                EditorGUILayout.LabelField("PCG Main Component is disabled!");
                return;
            }
            propertyName = EditorGUILayout.TextField("Target Model Name: ", propertyName);
            boxParent    = EditorGUILayout.ObjectField("Box Parent: ", boxParent, typeof(Transform), true) as Transform;
            updateRandom = EditorGUILayout.Toggle("Update Random Seed: ", updateRandom);
            if (!boxParent)
            {
                return;
            }
            Random rd = new Random((uint)System.Guid.NewGuid().GetHashCode());

            if (GUILayout.Button("Generate Random Nodes"))
            {
                int index = -1;
                for (int i = 0; i < res.allNodes.Count; ++i)
                {
                    if (res.allNodes[i].name == propertyName)
                    {
                        index = i;
                        break;
                    }
                }
                if (index < 0)
                {
                    Debug.Log("No Such Node Name!");
                    return;
                }
                int childCount = boxParent.childCount;
                for (int i = 0; i < childCount; ++i)
                {
                    Transform tr = boxParent.GetChild(i);
                    if (!tr.gameObject.activeSelf)
                    {
                        continue;
                    }
                    tr.gameObject.SetActive(false);
                    int randIndex = abs(rd.NextInt());
                    randIndex %= res.allNodes[index].objs.Count;
                    GameObject  newObj = Instantiate(res.allNodes[index].objs[randIndex], tr.position, tr.rotation, boxParent);
                    PCGNodeBase node   = newObj.GetComponent <PCGNodeBase>();
                    if (updateRandom)
                    {
                        node.RandomSeed = rd.NextUInt();
                    }
                    float3 extent = node.GetBounds().extents;
                    float3 scale  = tr.localScale * 0.5f;
                    scale /= extent;
                    node.transform.localScale = scale;
                    node.UpdateSettings();
                }
            }
            if (GUILayout.Button("Clear Nodes"))
            {
                int childCount = boxParent.childCount;
                for (int i = 0; i < min(boxParent.childCount, childCount); ++i)
                {
                    Transform tr = boxParent.GetChild(i);
                    if (tr.GetComponent <PCGNodeBase>())
                    {
                        DestroyImmediate(tr.gameObject);
                        i--;
                    }
                    else
                    {
                        tr.gameObject.SetActive(true);
                    }
                }
            }
        }