Пример #1
0
        public void SetWhiteMaterial()
        {
            BigWorldData bigdata = new BigWorldData();

            bigdata.bigdatas = new List <BigWorldModelData>();
            int childCount = m_Root.transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                Transform childTran = m_Root.transform.GetChild(i);
                if (childTran.name.Contains("Group"))
                {
                    MeshRenderer[] renders = childTran.GetComponentsInChildren <MeshRenderer>();
                    for (int j = 0; j < renders.Length; j++)
                    {
                        if (renders[j].name.Equals("wall"))
                        {
                            continue;
                        }
                        BigWorldModelData modelData = new BigWorldModelData();
                        modelData.path = childTran.name + "/" + renders[j].name;
                        modelData.mat  = renders[j].sharedMaterial.name + ".mat";
                        bigdata.bigdatas.Add(modelData);
                        renders[j].sharedMaterial = this.m_whiteMat;
                    }
                }
            }
            AssetDatabase.SaveAssets();
            string       jsonStr = fastJSON.JSON.ToJSON(bigdata);
            StreamWriter writer  = new StreamWriter(CreateWhiteModel.BigWorldInfo, false, System.Text.Encoding.Default);

            writer.Write(jsonStr);
            writer.Close();
        }
Пример #2
0
    public static void CreateModelMaxWidth()
    {
        GameObject[] selectObj = Selection.gameObjects;
        for (int i = 0; i < selectObj.Length; i++)
        {
            GameObject        currentObj = selectObj[i];
            BigWorldModelData modelData  = currentObj.GetComponent <BigWorldModelData>();
            if (currentObj != null)
            {
                GameObject.DestroyImmediate(modelData);
            }
            MeshFilter filter = currentObj.GetComponent <MeshFilter>();
            if (filter == null)
            {
                continue;
            }
            Mesh    mesh     = filter.sharedMesh;
            Vector3 meshSize = mesh.bounds.size;
            Vector3 scale    = currentObj.transform.lossyScale;
            float   maxDis   = Mathf.Max(meshSize.x * scale.x, meshSize.z * scale.z);
            //Quaternion quater = currentObj.transform.rotation;
            //Debug.Log(quater.eulerAngles);
            Vector3            centerPos  = currentObj.transform.rotation * mesh.bounds.center;//Quaternion.Euler(90,180,0) * currentObj.transform.position;
            BigWorldDimianData dimianData = currentObj.GetComponent <BigWorldDimianData>();
            if (dimianData == null)
            {
                dimianData = currentObj.AddComponent <BigWorldDimianData>();
            }
            dimianData.m_centerPos = centerPos;
            dimianData.m_maxDis    = maxDis;

            //Debug.Log("center : " + GetCenterPos(mesh));
        }
    }
Пример #3
0
 public static void GetModelHei()
 {
     GameObject[] selectObj = Selection.gameObjects;
     for (int i = 0; i < selectObj.Length; i++)
     {
         GameObject     objRoot     = selectObj[i];
         MeshRenderer[] childRender = objRoot.GetComponentsInChildren <MeshRenderer>();
         float          groupMinHei = 0f;
         float          groupMaxHei = 0f;
         for (int j = 0; j < childRender.Length; j++)
         {
             if (childRender[j].name.Equals("center") || childRender[j].name.Equals("Cube"))
             {
                 continue;
             }
             GameObject obj    = childRender[j].gameObject;
             MeshFilter filter = obj.GetComponent <MeshFilter>();
             if (filter == null)
             {
                 continue;
             }
             Mesh              mesh       = filter.sharedMesh;
             Vector3           meshSize   = mesh.bounds.size;
             Vector3           scale      = obj.transform.lossyScale;
             float             yyy        = meshSize.z * scale.y;
             BigWorldModelData modelParam = obj.GetComponent <BigWorldModelData>();
             if (modelParam == null)
             {
                 modelParam = obj.AddComponent <BigWorldModelData>();
             }
             modelParam.maxHei = yyy;
             float childMinHei = obj.transform.position.y - yyy / 2f;
             float childMaxHei = obj.transform.position.y + yyy / 2f;
             if (j == 0)
             {
                 groupMinHei = childMinHei;
                 groupMaxHei = childMaxHei;
             }
             else
             {
                 groupMinHei = Mathf.Min(groupMinHei, childMinHei);
                 groupMaxHei = Mathf.Max(groupMaxHei, childMaxHei);
             }
         }
         BigWorldGroupData groupdata = objRoot.GetComponent <BigWorldGroupData>();
         if (groupdata == null)
         {
             groupdata            = objRoot.AddComponent <BigWorldGroupData>();
             groupdata.m_startPos = 6.3f;//groupMinHei - 0.5f;
             groupdata.m_endPos   = groupMaxHei + 0.1f;
         }
     }
 }
Пример #4
0
        //播放解锁
        private void PlayUnLockEffect(Action callback = null)
        {
            EngineCoreEvents.AudioEvents.PlayAudio.SafeInvoke(Audio.AudioType.UISound, GameCustomAudioKey.unlock_success.ToString());
            BigWorldGroupData groupData = this.m_buildObj.GetComponent <BigWorldGroupData>();

            if (groupData == null)
            {
                Debug.LogError("group data error");
                return;
            }
            List <Material> mats = new List <Material>();
            Dictionary <MeshRenderer, Material> m_srcMats = new Dictionary <MeshRenderer, Material>();

            //List<Material> m_srcMats = new List<Material>();
            //Material m_dimianMat = null;
            //BigWorldDimianData dimianData = null;
            //Material dimainMat = null;
            MeshRenderer[] renderer = m_buildObj.transform.GetComponentsInChildren <MeshRenderer>();
            for (int i = 0; i < renderer.Length; i++)
            {
                Material          mat       = renderer[i].sharedMaterial;
                BigWorldModelData modelData = renderer[i].gameObject.GetComponent <BigWorldModelData>();
                if (modelData != null)
                {
                    renderer[i].material = m_unlockMaterial;
                    renderer[i].material.SetFloat("_MaxHei", modelData.maxHei);
                    renderer[i].material.SetTexture("_MainTex", mat.GetTexture("_MainTex"));
                    renderer[i].material.SetTexture("_LightMapTex", mat.GetTexture("_NightTex"));
                    //render.material.SetFloat("_LightLerp", mat.GetFloat("_lerp"));
                    mats.Add(renderer[i].material);
                }
                m_srcMats.Add(renderer[i], BigWorldGameObject.GetBuildCommonMatByName(mat.name + ".mat"));
            }


            groupData.PlayEffect(mats, () =>
            {
                TimeModule.Instance.SetTimeout(() =>
                {
                    foreach (var kv in m_srcMats)
                    {
                        kv.Key.sharedMaterial = kv.Value;
                    }
                    this.m_unLockEffect.transform.SetParent(this.m_buildObj.transform);
                    this.m_unLockEffect.transform.localPosition = Vector3.zero;
                    //this.m_unLockEffect.transform.position = m_buildObj.transform.position; //+ Vector3.up * 0.1f

                    this.m_unLockEffect.transform.localPosition += groupData.m_FuncPos;
                    this.m_unLockEffect.scale = groupData.m_EffectScale;
                    this.m_unLockEffect.gameObject.SetActive(true);
                    TimeModule.Instance.SetTimeout(() => { this.m_unLockEffect.gameObject.SetActive(false); }, 2f);
                    Dictionary <UBSParamKeyName, object> _params = new Dictionary <UBSParamKeyName, object>()
                    {
                        { UBSParamKeyName.ContentID, BuildID },
                        { UBSParamKeyName.ContentType, "unLock" },
                        { UBSParamKeyName.Description, DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss:ms") },
                    };
                    UserBehaviorStatisticsModules.Instance.LogEvent(UBSEventKeyName.build_plan, null, _params);

                    GameObject.DestroyImmediate(groupData);

                    GameEvents.BigWorld_Event.OnBuildUnLockComplete.SafeInvoke(BuildID);
                    if (callback != null)
                    {
                        callback();
                    }
                }, 1f);
            });
        }