Ejemplo n.º 1
0
    /// <summary>
    /// JSON转换为多个对象.
    /// </summary>
    private void JsonToObject()
    {
        string jsonStr = File.ReadAllText(jsonPath);

        JsonData jsonData = JsonMapper.ToObject(jsonStr);

        for (int i = 0; i < jsonData.Count; ++i)
        {
            BuildItem item = JsonMapper.ToObject <BuildItem>(jsonData[i].ToJson());
            jsonList.Add(item);
        }

        for (int i = 0; i < jsonList.Count; ++i)
        {
            Vector3    pos = new Vector3(float.Parse(jsonList[i].PosX), float.Parse(jsonList[i].PosY), float.Parse(jsonList[i].PosZ));
            Quaternion rot = new Quaternion(float.Parse(jsonList[i].RotX), float.Parse(jsonList[i].RotY), float.Parse(jsonList[i].RotZ), float.Parse(jsonList[i].RotW));

            prefab_Model = Resources.Load <GameObject>("BuildModule/BuildModels/" + jsonList[i].Name);
            GameObject buildModel = GameObject.Instantiate <GameObject>(prefab_Model, pos, rot, m_Transform);

            // 初始化逻辑.
            buildModel.name  = jsonList[i].Name;
            buildModel.layer = LayerMask.NameToLayer("BuildModelEnd");
            MaterialModelBase mmb = buildModel.GetComponent <MaterialModelBase>();
            mmb.NormalModel();
            GameObject.Destroy(mmb);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 鼠标左键事件.
    /// </summary>
    private void LeftMouseButtonDown()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // 第一个空白区域相当于切换建造材料使用.
            if (currentItem == categoryItemList[0])
            {
                SetMaterialToNull();
                return;
            }

            if (currentMaterialModel == null)
            {
                isCategoryCtrl = false;
            }

            // 有建造材料模型, 隐藏建造UI.
            if (currentMaterialModel != null && isUIShow)
            {
                m_BuildPanelView.WheelBG_Transform.gameObject.SetActive(false);
                isUIShow       = false;
                isCategoryCtrl = true;
            }

            // 将实例化的材料回归默认颜色, 如果不能生成就直接退出.
            MaterialModelBase mmb = null;
            if (materialModel != null && !(mmb = materialModel.GetComponent <MaterialModelBase>()).CanPut)
            {
                return;
            }
            else if (materialModel != null && mmb.CanPut)
            {
                materialModel.name  = currentMaterialModel.name;
                materialModel.layer = LayerMask.NameToLayer("BuildModelEnd");
                mmb.NormalModel();
                GameObject.Destroy(mmb);
            }

            // 实例化建造材料.
            if (currentMaterialModel != null)
            {
                materialModel = GameObject.Instantiate <GameObject>(currentMaterialModel,
                                                                    m_BuildPanelView.Player_Transform.position + Vector3.forward * 10,
                                                                    Quaternion.identity, m_BuildPanelView.BuildModelsParent);
            }
        }
    }