Exemple #1
0
    GameObject NewTrileObject(TrileEmplacement atPos)
    {
        TrileInstance instance;

        if (loaded.Triles.ContainsKey(atPos))
        {
            instance = loaded.Triles[atPos];
        }
        else
        {
            instance          = new TrileInstance();
            instance.TrileId  = currTrileID;
            instance.Position = new Vector3(atPos.X, atPos.Y, atPos.Z);
            loaded.Triles.Add(atPos, instance);
        }

        GameObject newTrile;

        if (trileObjectCache.Count > 0)
        {
            newTrile = trileObjectCache[0];
            trileObjectCache.RemoveAt(0);
            newTrile.SetActive(true);
        }
        else
        {
            newTrile = Instantiate(trilePrefab);
        }

        MeshFilter    mf = newTrile.GetComponent <MeshFilter>();
        MeshRenderer  mr = newTrile.GetComponent <MeshRenderer>();
        BoxCollider   bc = newTrile.GetComponent <BoxCollider>();
        TrileImported tI = newTrile.GetComponent <TrileImported>();

        tI.myInstance = instance;

        mr.material = setMat;
        mf.mesh     = trilesetCache[s.Triles[instance.TrileId]];

        newTrile.transform.position = new Vector3(atPos.X, atPos.Y, atPos.Z);
        newTrile.transform.rotation = Quaternion.Euler(0, Mathf.Rad2Deg * instance.Data.PositionPhi.w, 0);

        newTrile.name             = s.Triles[instance.TrileId].Name;
        newTrile.transform.parent = transform.FindChild("Triles");
        if (!trileObjects.ContainsKey(atPos))
        {
            trileObjects.Add(atPos, newTrile);
        }
        else
        {
            trileObjects[atPos] = newTrile;
        }
        return(newTrile);
    }
Exemple #2
0
    void PropertiesEditorMode()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit rh;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rh))
            {
                if (rh.transform.tag == "Trile")
                {
                    lastTrile   = rh.transform.GetComponent <TrileImported>();
                    trileBounds = LevelManager.Instance.getTrileBounds(lastTrile.myInstance.TrileId);
                    isTrile     = true;
                    ObjectProperties.Instance.SetToTrile(lastTrile.myInstance.TrileId);
                }
                else if (rh.transform.tag == "ArtObject")
                {
                    lastAO   = rh.transform.GetComponent <ArtObjectImported>();
                    aoBounds = LevelManager.Instance.getAOBounds(lastAO.myInstance.ArtObjectName);
                    isTrile  = false;
                    ObjectProperties.Instance.SetToAO(lastAO.myInstance.ArtObjectName);
                }
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            //PropertiesEditor.Instance.SelectLevel();
        }

        if (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Delete))
        {
            if (isTrile)
            {
                LevelManager.Instance.RemoveTrile(new TrileEmplacement((int)lastTrile.transform.position.x, (int)lastTrile.transform.position.y, (int)lastTrile.transform.position.z));
            }
            else
            {
                LevelManager.Instance.RemoveAO(lastAO);
            }

            return;
        }

        //If we right click

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit rh;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rh))
            {
                if (rh.transform.tag == "Trile")
                {
                    if (lastTrile == null)
                    {
                        isTrile     = true;
                        lastTrile   = rh.transform.GetComponent <TrileImported>();
                        trileBounds = LevelManager.Instance.getTrileBounds(lastTrile.myInstance.TrileId);
                    }
                    else if (rh.transform != lastTrile.transform)
                    {
                        isTrile     = true;
                        lastTrile   = rh.transform.GetComponent <TrileImported>();
                        trileBounds = LevelManager.Instance.getTrileBounds(lastTrile.myInstance.TrileId);
                    }
                }
                else if (rh.transform.tag == "ArtObject")
                {
                    if (lastAO == null)
                    {
                        isTrile  = false;
                        lastAO   = rh.transform.GetComponent <ArtObjectImported>();
                        aoBounds = LevelManager.Instance.getAOBounds(lastAO.myInstance.ArtObjectName);
                    }
                    else if (rh.transform != lastAO.transform)
                    {
                        isTrile  = false;
                        lastAO   = rh.transform.GetComponent <ArtObjectImported>();
                        aoBounds = LevelManager.Instance.getAOBounds(lastAO.myInstance.ArtObjectName);
                    }
                }
                objectDragging.SetNormalAndPosition(rh.normal, rh.point);
            }

            if (isTrile)
            {
                if (lastTrile == null)
                {
                    return;
                }

                preTrileMove = new TrileEmplacement((int)lastTrile.transform.position.x, (int)lastTrile.transform.position.y, (int)lastTrile.transform.position.z);
                lastTrile.GetComponent <BoxCollider>().enabled = false;
            }
            else
            {
                if (lastAO == null)
                {
                    return;
                }

                lastAO.GetComponent <MeshCollider>().enabled = false;
            }
        }

        if (Input.GetMouseButton(1))
        {
            distOffset -= Input.mouseScrollDelta.y / 13;

            distOffset = Mathf.Clamp(distOffset, -1, 1);

            RaycastHit rh;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rh) && !Input.GetKey(KeyCode.Space))
            {
                objectDragging.SetNormalAndPosition(rh.normal, rh.point);
            }

            if (isTrile)
            {
                if (lastTrile == null)
                {
                    return;
                }

                float pos;

                Ray cam = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (objectDragging.Raycast(cam, out pos))
                {
                    lastTrile.transform.position  = cam.GetPoint(pos) + (objectDragging.normal / 2);
                    lastTrile.transform.position += trileBounds.center;
                    lastTrile.transform.position += objectDragging.normal * distOffset;
                }
            }
            else
            {
                if (lastAO == null)
                {
                    return;
                }

                float pos;

                Ray cam = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (objectDragging.Raycast(cam, out pos))
                {
                    lastAO.transform.position  = cam.GetPoint(pos) - (objectDragging.normal / 2);
                    lastAO.transform.position += aoBounds.center;
                    lastAO.transform.position += objectDragging.normal * distOffset;
                }
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            if (isTrile)
            {
                if (lastTrile == null)
                {
                    return;
                }

                lastTrile.transform.position = roundToGrid(1, lastTrile.transform.position);
                TrileEmplacement newPlacment = new TrileEmplacement(Mathf.FloorToInt(lastTrile.transform.position.x), Mathf.RoundToInt(lastTrile.transform.position.y), Mathf.RoundToInt(lastTrile.transform.position.z));

                if (LevelManager.Instance.isOccupied(newPlacment))
                {
                    Debug.Log("Trile exists at " + new Vector3(newPlacment.X, newPlacment.Y, newPlacment.Z) + " id is " + LevelManager.Instance.loaded.Triles[newPlacment].TrileId);
                    lastTrile.transform.position = new Vector3(preTrileMove.X, preTrileMove.Y, preTrileMove.Z);
                    lastTrile.GetComponent <BoxCollider>().enabled = true;
                }
                else
                {
                    LevelManager.Instance.MoveTrile(preTrileMove, newPlacment, lastTrile.myInstance);
                    lastTrile.GetComponent <BoxCollider>().enabled = true;
                }
            }
            else
            {
                if (lastAO == null)
                {
                    return;
                }

                lastAO.transform.position = roundToGrid(16, lastAO.transform.position);
                LevelManager.Instance.MoveAO(lastAO.myInstance.Id, lastAO.transform.position);
                lastAO.GetComponent <MeshCollider>().enabled = true;
            }
        }

        //If we middle click
        if (Input.GetMouseButton(2))
        {
            if (isTrile)
            {
                if (lastTrile == null)
                {
                    return;
                }

                lastTrile.transform.rotation = Quaternion.Euler(0, lastTrile.transform.eulerAngles.y - Input.GetAxis("Mouse X") * 5, 0);
            }
            else
            {
                if (lastAO == null)
                {
                    return;
                }

                lastAO.transform.rotation = Quaternion.Euler(0, lastAO.transform.eulerAngles.y - Input.GetAxis("Mouse X") * 5, 0);
            }
        }

        //If we let go of middle click
        if (Input.GetMouseButtonUp(2))
        {
            if (isTrile)
            {
                if (lastTrile == null)
                {
                    return;
                }

                lastTrile.transform.rotation = Quaternion.Euler(0, Mathf.RoundToInt(lastTrile.transform.eulerAngles.y / 90) * 90, 0);
            }
            else
            {
                if (lastAO == null)
                {
                    return;
                }

                lastAO.transform.rotation = Quaternion.Euler(0, Mathf.RoundToInt(lastAO.transform.eulerAngles.y / 90) * 90, 0);
            }
        }
    }