예제 #1
0
    public Mesh ReMeshBase(IEnumerable <BlockQuad> blockQuads, out Material[] issuedMaterials)
    {
        // MaterilaName/ Array of material corresponding meshFilters
        Dictionary <string, MeshCombines> combineinstanceNew = new Dictionary <string, MeshCombines>();

        // Enumerate Block Quads to fill combine meshes
        {
            foreach (BlockQuad blockQuad in blockQuads)
            {
                CombineInstance instance = default;

                instance.mesh      = blockQuad.MeshFilter.sharedMesh;
                instance.transform = blockQuad.MeshFilter.transform.localToWorldMatrix;



                CubeDescription cubeDescription = StaticWorld.Instance.CubeDescriptions[blockQuad.BlockType];
                Material        material        = cubeDescription.CubeContent[blockQuad.Cubeside];

                string key = material.name;

                if (!combineinstanceNew.ContainsKey(key))
                {
                    combineinstanceNew.Add(key, new MeshCombines {
                        Materials = new List <Material>()
                    });
                }

                combineinstanceNew[key].Materials.Add(material);
                combineinstanceNew[key].Add(instance);
            }
        }


        Mesh[] meshes = new Mesh[combineinstanceNew.Count];

        HashSet <Material> materialsHashSet = new HashSet <Material>();


        // Enumerate dictionary to define materials and mehses
        {
            for (int i = 0; i < combineinstanceNew.Count; i++)
            {
                MeshCombines tempColl = combineinstanceNew.ElementAt(i).Value;

                foreach (Material material in tempColl.Materials)
                {
                    materialsHashSet.Add(material);
                }

                Mesh mesh = new Mesh();
                mesh.CombineMeshes(tempColl.ToArray(), true, true);
                meshes[i] = mesh;
            }
        }

        issuedMaterials = materialsHashSet.ToArray();

        return(Combine(meshes.ToArray()));
    }
        public void replaceCubeNodeAndCleanOld(Vector2 replacePosition, CubeDescription cubeDescription)
        {
            cleanUpNodeAt(replacePosition);
            CubeNode toReplace = createNode(cubeDescription);

            cubeLookUp[replacePosition] = toReplace;
            if (selectedCube.Value == replacePosition)
            {
                getSelectedNode().deselect();
                toReplace.select();
            }
        }
예제 #3
0
        public void SetType(BlockType b)
        {
            BlockType oldType = this.Type;

            this.Type = b;

            this.Kind = StaticWorld.Instance.CubeDescriptions[this.Type].blockKind;

            // CUBE GAMEOBJECTS
            GameObject[] tempGameObjects = null;

            if (this.Type != BlockType.AIR)
            {
                CubeDescription cubeDescription = StaticWorld.Instance.CubeDescriptions[this.Type];

                tempGameObjects = cubeDescription.cubeGameObjects;
            }
            else
            {
                tempGameObjects = new GameObject[0];
            }

            // ADDITIONAL OBJECTS
            this.BlockObjects?.ToList().ForEach(Object.Destroy);

            this.BlockObjects = new GameObject[tempGameObjects.Length];

            for (int index = 0; index < tempGameObjects.Length; index++)
            {
                GameObject cubeGameObject = tempGameObjects[index];

                GameObject obj = Object.Instantiate(cubeGameObject);

                obj.transform.position = this.Position;
                obj.AddComponent <ObjectPosition>().Position = this.Position;

                obj.transform.position   *= StaticWorld.K;
                obj.transform.localScale *= StaticWorld.K;

                Light light = obj.GetComponentInChildren <Light>();
                if (light != null)
                {
                    light.range *= StaticWorld.K;
                }

                obj.transform.SetParent(this.ParentTransform, false);

                this.BlockObjects[index] = obj;
            }
        }
        public bool addCubeNodeFromTo(Vector2 fromPosition, Vector2 targetPosition, CubeDescription cubeDescription)
        {
            CubeNode nodeToAdd = createNode(cubeDescription);

            if (!addCubeNodeAtPossible(targetPosition))
            {
                return(false); // already has a block in target position
            }
            else
            {
                nodeToAdd.positionIndex    = targetPosition;
                cubeLookUp[targetPosition] = nodeToAdd;

                if (cubeDescription.type == CubeType.ChainCube)
                {
                    ChainCube chain = (ChainCube)nodeToAdd;
                    ChainPhysicsGameObject chainPhys = (ChainPhysicsGameObject)chain.physicalObject;
                    for (int i = 0; i < 10; i++)
                    {
                        chainPhys.path.Add(new Vector2(
                                               fromPosition.X + (i * (targetPosition.X - fromPosition.X) / 10f),
                                               fromPosition.Y + (i * (targetPosition.Y - fromPosition.Y) / 10f)));
                    }
                    chainPhys.makeLink();
                }
                nodeToAdd.physicalObject.boxBody.Position =
                    getRootNode().physicalObject.boxBody.Position + getRealPosition(targetPosition, cubeSize);

                // joining up blocks (from fromPosition to targetPosition)
                //physicsController.registerPhysicsGameJoint(new PhysicsGameJoint(physicsController.physicsSimulator, this.cubeLookUp[fromPosition].physicalObject, nodeToAdd.physicalObject));

                foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                {
                    Vector2 neighbourIndex = adjacentIndex(targetPosition, dir);
                    if (cubeLookUp.ContainsKey(neighbourIndex)) // TODO check for duplicate joints
                    {
                        physicsController.registerPhysicsGameJoint(new PhysicsGameJoint(physicsController.physicsSimulator, cubeLookUp[neighbourIndex].physicalObject, nodeToAdd.physicalObject));
                    }
                }

                return(true);
            }
        }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (this.blockType != this.blockInteraction.blockType)
        {
            this.blockType = this.blockInteraction.blockType;

            CubeDescription description = StaticWorld.Instance.CubeDescriptions[this.blockType.Value];

            Material  m   = description.previewMaterial;
            Texture2D tex = (Texture2D)m.mainTexture;

            this.image.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);

            if (m.HasProperty("_Color"))
            {
                this.image.color = m.GetColor("_Color");
            }
        }
    }
예제 #6
0
    void Start()
    {
        // just for testing...
        this.backupScale = this.transform.localScale;


        this.PanelState = PanelStates.IN_BACKGROUND;

        Vector3    backupPosition = this.transform.position;
        Quaternion backupRotation = this.transform.rotation;

        this.transform.position = Vector3.zero;
        this.transform.rotation = Quaternion.identity;

        string txt = this.JSONFile.text;

        string[] lines = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
        // Make sure there are no empty lines in the json file...
        // It reads from Assets>>Resources>>JSONStuff and the file name is SampleData
        SampleData[] data = new SampleData[lines.Length];

        for (int i = 0; i < lines.Length; i++)
        {
            //keep in mind that ids are not unique at the moement, you can have for instance multiple instance of 'anatolian_sheperd_dog' in a single panel
            data[i] = JsonUtility.FromJson <SampleData>(lines[i]);
            //UnityEngine.Debug.Log(lines[i]);
            //UnityEngine.Debug.Log("Lines Are: " + lines[i]);
        }

        this.SubComponents = new Dictionary <string, GameObject>();
        Material textureMaterial = Resources.Load("DefMaterial") as Material;

        // an example for random placement on certain predefined positions
        float xOffset = .5f;
        float yOffset = .5f;

        List <Vector3> positions     = new List <Vector3>();
        Vector3        scale         = this.transform.localScale;
        float          scalingFactor = .25f;


        for (float x = this.transform.position.x - scale.x * .5f + xOffset; x < this.transform.position.x + scale.x * .5f; x += 1.0f * scalingFactor)
        {
            for (float y = this.transform.position.y - scale.y * .5f + yOffset; y < this.transform.position.y + scale.y * .5f; y += 1.0f * scalingFactor)
            {
                positions.Add(new Vector3(x, y, 0.1f));
            }
        }

        //Following part is for rendering the images on cubes surrounding the panel(door)

        for (int i = 0; i < data.Length; i++)
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
            go.transform.position = this.transform.position;
            go.transform.rotation = this.transform.rotation;
            var rend = go.GetComponent <Renderer>();
            rend.material = Instantiate(textureMaterial) as Material;
            UnityEngine.Debug.Log(data[i].fileName);
            Texture tex = Resources.Load("Images/" + data[i].fileName) as Texture;//From Resources folder (Resources.) ...
            Debug.Log("Dim for " + data[i].fileName + " : " + tex.height + " x " + tex.width);
            if (tex != null)
            {
                rend.material.mainTexture = tex;
            }
            //go.transform.localScale = new Vector3(data[i].width * scalingFactor, data[i].height * scalingFactor, 1.0f);
            float baseScale = Mathf.Min(tex.width, tex.height);
            go.transform.localScale = new Vector3(tex.width / baseScale * scalingFactor, tex.height / baseScale * scalingFactor, 0.1f);
            go.transform.parent     = this.transform;

            int index = UnityEngine.Random.Range(0, positions.Count);
            go.transform.position = positions[index];
            positions.RemoveAt(index);

            go.name = data[i].ID;

            if (this.GetComponent <ContentPositioning>())
            {
                this.GetComponent <ContentPositioning>().LayoutContent(go, i, this);
            }

            /*
             * Vector3 center = this.GetComponent<MeshRenderer>().bounds.center;
             * Vector3 extents = this.GetComponent<MeshRenderer>().bounds.extents;
             *
             * go.transform.position = center + new Vector3(data[i].xPosition * extents.x, data[i].yPosition * extents.y, extents.z);
             */

            GameObject description = GameObject.Instantiate(this.DescriptionPrefab);

            /*description.transform.position = go.transform.position + new Vector3(go.transform.localScale.x * 1.1f, 0.0f, 0.0f);
             * description.transform.rotation = go.transform.rotation;
             * description.transform.parent = go.transform;*/
            // description.transform.position = this.transform.position + new Vector3(0.0f, 0.5f, 1.0f);


            description.transform.position       = go.transform.position;
            description.transform.rotation       = go.transform.rotation;
            description.transform.parent         = go.transform;
            description.transform.localPosition += new Vector3(0.0f, go.transform.localScale.y * 2.1f, go.transform.localScale.z * 1.1f);


            //Then it will shows up corresponding text messages to each image as read from epoch
            if (description.GetComponentInChildren <UnityEngine.UI.Text>())
            {
                description.GetComponentInChildren <UnityEngine.UI.Text>().text = data[i].epoch;
            }
            GameObject imageFrame = GameObject.Instantiate(this.ImageFrame);
            imageFrame.transform.position   = go.transform.position;
            imageFrame.transform.rotation   = go.transform.rotation;
            imageFrame.transform.parent     = go.transform;
            imageFrame.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);


            //Script for Cube Description is already created
            CubeDescription descriptionScript = go.AddComponent <CubeDescription>();
            if (description.GetComponentInChildren <UnityEngine.UI.Text>())
            {
                descriptionScript.description = description.GetComponentInChildren <UnityEngine.UI.Text>();
            }
            descriptionScript.data = data[i];

            descriptionScript.ImageFrame = imageFrame;
            imageFrame.SetActive(false);



            GazeBasedDetailButton buttonScript = null;

            for (int j = 0; j < description.transform.childCount; j++)
            {
                if (description.transform.GetChild(j).name == "ButtonPlaceHolder")
                {
                    GameObject placeHolder = description.transform.GetChild(j).gameObject;
                    //placeHolder.transform.localPosition += new Vector3(0.0f, -description.transform.localScale.y * 1.1f, 0.0f);
                    placeHolder.transform.position       = go.transform.position - new Vector3(go.GetComponent <MeshRenderer>().bounds.extents.x * 1.0f, go.GetComponent <MeshRenderer>().bounds.extents.y * 1.1f, 0.0f);
                    placeHolder.transform.localPosition += new Vector3(0.0f, 0.0f, go.transform.localScale.z * 3.1f);
                    descriptionScript.button             = placeHolder;
                    buttonScript = placeHolder.AddComponent <GazeBasedDetailButton>();
                    placeHolder.SetActive(false);
                }
            }


            if (this.DetailsPrefab)
            {
                GameObject details = GameObject.Instantiate(this.DetailsPrefab);
                details.transform.position = go.transform.position;
                details.transform.rotation = go.transform.rotation;
                details.transform.parent   = go.transform;
                // scale according to the image
                //details.transform.localScale = go.transform.localScale;
                details.transform.localPosition += new Vector3(0.0f, 0.0f, go.transform.localScale.z * 1.1f);

                details.SetActive(true);

                Text detailsText = details.GetComponentInChildren <Text>();
                detailsText.text = data[i].fileName + "\n" + data[i].epoch;

                if (buttonScript)
                {
                    buttonScript.TextDescription = details;
                }

                if (details.GetComponent <RectTransform>())
                {
                    RectTransform rectangle = details.GetComponent <RectTransform>();
                    float         xScale    = rectangle.rect.width * go.transform.localScale.x;
                    float         yScale    = rectangle.rect.height * go.transform.localScale.y;

                    for (int j = 0; j < details.transform.childCount; j++)
                    {
                        if (details.transform.GetChild(j).GetComponent <RectTransform>())
                        {
                            RectTransform cRectangle = details.transform.GetChild(j).GetComponent <RectTransform>();
                            cRectangle.sizeDelta = new Vector2(xScale, yScale);
                        }
                        else
                        {
                            Vector3 currentScale = details.transform.GetChild(j).transform.localScale;
                            currentScale.x = xScale;
                            currentScale.y = yScale;
                            details.transform.GetChild(j).transform.localScale = currentScale;
                        }
                    }
                }

                details.SetActive(false);
            }

            if (this.ButtonPrefab)
            {
            }

            this.SubComponents.Add(data[i].ID, go);
        }

        this.transform.position = backupPosition;
        this.transform.rotation = backupRotation;
    }
 public bool addCubeNodeFrom(Vector2 fromPosition, Direction dir, CubeDescription cubeDescription)
 {
     return(addCubeNodeFromTo(fromPosition, adjacentIndex(cubeLookUp[fromPosition].positionIndex, dir), cubeDescription));
 }
        public CubeNode createNode(CubeDescription cubeDescription)
        {
            CubeNode temp = CubeFactory.createCubeNode(textureStore, physicsController, cubeDescription, cubeSize, this);

            return(temp);
        }