Esempio n. 1
0
    ///<summary>
    /// Deserialize a SInteract command and run it.
    ///</summary>
    ///<param name="_data">The serialized command to execute</param>
    private void InteractWithObject(string _data)
    {
        List <string> usableParams;
        SInteract     command = JsonConvert.DeserializeObject <SInteract>(_data);
        OgreeObject   obj     = Utils.GetObjectById(command.id).GetComponent <OgreeObject>();

        switch (obj.category)
        {
        case "room":
            Room room = (Room)obj;
            usableParams = new List <string>()
            {
                "tilesName", "tilesColor"
            };
            if (usableParams.Contains(command.param))
            {
                room.SetAttribute(command.param, command.value);
            }
            else
            {
                Debug.LogWarning("Incorrect room interaction");
            }
            break;

        case "rack":
            Rack rack = (Rack)obj;
            usableParams = new List <string>()
            {
                "label", "labelFont", "alpha", "slots", "localCS", "U"
            };
            if (usableParams.Contains(command.param))
            {
                rack.SetAttribute(command.param, command.value);
            }
            else
            {
                Debug.LogWarning("Incorrect rack interaction");
            }
            break;

        case "device":
            OObject device = (OObject)obj;
            usableParams = new List <string>()
            {
                "label", "labelFont", "alpha", "slots", "localCS"
            };
            if (usableParams.Contains(command.param))
            {
                device.SetAttribute(command.param, command.value);
            }
            else
            {
                Debug.LogWarning("Incorrect device interaction");
            }
            break;

        default:
            GameManager.gm.AppendLogLine("Unknown category to interact with", true, eLogtype.warning);
            break;
        }
    }
Esempio n. 2
0
    ///<summary>
    /// Generate a corridor (from GameManager.labeledBoxModel) with defined corners and color.
    ///</summary>
    ///<param name="_co">The corridor data to apply</param>
    ///<param name="_parent">The parent of the created corridor. Leave null if _co contains the parendId</param>
    ///<returns>The created corridor</returns>
    public OObject CreateCorridor(SApiObject _co, Transform _parent = null)
    {
        Transform parent = Utils.FindParent(_parent, _co.parentId);

        if (!parent || parent.GetComponent <OgreeObject>().category != "room")
        {
            GameManager.gm.AppendLogLine($"Parent room not found", true, eLogtype.error);
            return(null);
        }

        string hierarchyName = $"{parent.GetComponent<OgreeObject>().hierarchyName}.{_co.name}";

        if (GameManager.gm.allItems.Contains(hierarchyName))
        {
            GameManager.gm.AppendLogLine($"{hierarchyName} already exists.", true, eLogtype.warning);
            return(null);
        }

        string roomHierarchyName = parent.GetComponent <OgreeObject>().hierarchyName;

        string[]  rackNames  = _co.attributes["content"].Split(',');
        Transform lowerLeft  = GameManager.gm.FindByAbsPath($"{roomHierarchyName}.{rackNames[0]}")?.transform;
        Transform upperRight = GameManager.gm.FindByAbsPath($"{roomHierarchyName}.{rackNames[1]}")?.transform;

        if (lowerLeft == null || upperRight == null)
        {
            GameManager.gm.AppendLogLine($"{rackNames[0]} or {rackNames[1]} doesn't exist", true, eLogtype.error);
            return(null);
        }

        float maxHeight = lowerLeft.GetChild(0).localScale.y;

        if (upperRight.GetChild(0).localScale.y > maxHeight)
        {
            maxHeight = upperRight.GetChild(0).localScale.y;
        }

        GameObject newCo = Instantiate(GameManager.gm.labeledBoxModel);

        newCo.name             = _co.name;
        newCo.transform.parent = parent;

        float x = upperRight.localPosition.x - lowerLeft.localPosition.x;
        float z = upperRight.localPosition.z - lowerLeft.localPosition.z;

        if (lowerLeft.GetComponent <Rack>().attributes["orientation"] == "front" ||
            lowerLeft.GetComponent <Rack>().attributes["orientation"] == "rear")
        {
            x += (upperRight.GetChild(0).localScale.x + lowerLeft.GetChild(0).localScale.x) / 2;
            z -= (upperRight.GetChild(0).localScale.z + lowerLeft.GetChild(0).localScale.z) / 2;
        }
        else
        {
            x += (upperRight.GetChild(0).localScale.z + lowerLeft.GetChild(0).localScale.z) / 2;
            z -= (upperRight.GetChild(0).localScale.x + lowerLeft.GetChild(0).localScale.x) / 2;
        }
        newCo.transform.GetChild(0).localScale = new Vector3(x, maxHeight, z);

        newCo.transform.localEulerAngles = new Vector3(0, 180, 0);
        newCo.transform.localPosition    = new Vector3(lowerLeft.localPosition.x, maxHeight / 2, lowerLeft.localPosition.z);
        float xOffset = (newCo.transform.GetChild(0).localScale.x - lowerLeft.GetChild(0).localScale.x) / 2;
        float zOffset = (newCo.transform.GetChild(0).localScale.z + lowerLeft.GetChild(0).localScale.z) / 2;

        newCo.transform.localPosition += new Vector3(xOffset, 0, zOffset);

        OObject co = newCo.AddComponent <OObject>();

        co.UpdateFromSApiObject(_co);

        newCo.transform.GetChild(0).GetComponent <Renderer>().material = GameManager.gm.alphaMat;
        Material mat = newCo.transform.GetChild(0).GetComponent <Renderer>().material;

        mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, 0.5f);
        if (_co.attributes["temperature"] == "cold")
        {
            co.SetAttribute("color", "000099");
        }
        else
        {
            co.SetAttribute("color", "990000");
        }

        newCo.GetComponent <DisplayObjectData>().PlaceTexts("top");
        newCo.GetComponent <DisplayObjectData>().SetLabel("#name");

        string hn = co.UpdateHierarchyName();

        GameManager.gm.allItems.Add(hn, newCo);

        return(co);
    }