Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        public void WriteBack(GameObject gameObject)
        {
            if (dirty)
            {
                gameObject.SetActive(activeSelf);
                gameObject.isStatic = isStatic;
                gameObject.layer    = layer;
                gameObject.tag      = tag;
                gameObject.name     = name;
            }

            // ComponentKun側がDirtyであるかいなかはComponentKun側に依存する
            for (var i = 0; i < componentKunTypes.Length; i++)
            {
                var componentKunType = componentKunTypes[i];
                if (componentKunType == ComponentKun.ComponentKunType.MissingMono)
                {
                    continue;
                }
                var systemType = ComponentKun.GetComponentSystemType(componentKunType);
                var component  = gameObject.GetComponent(systemType);

                //UnityChoseKun.Log(componentKunType);

                if (component == null)
                {
                    UnityChoseKun.LogWarning("component == null");
                    continue;
                }
                componentKuns[i].WriteBack(component);
                componentKuns[i].dirty = false;
            }

            dirty = false;
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        public void WriteBack(GameObject gameObject)
        {
            if (dirty)
            {
                gameObject.SetActive(activeSelf);
                gameObject.isStatic = isStatic;
                gameObject.layer    = layer;
                gameObject.tag      = tag;
                gameObject.name     = name;
            }

            // instanceIDが一致するComponetを探し出してWriteBackを実行する。
            // ※ComponentKun側がDirtyであるかいなかはGameObjectKunではなく各ComponentKun側に依存する
            var components = gameObject.GetComponents <Component>();

            for (var i = 0; i < componentKunTypes.Length; i++)
            {
                var componentKunType = componentKunTypes[i];
                if (componentKunType == ComponentKun.ComponentKunType.MissingMono)
                {
                    continue;
                }
                Component component = null;
                for (var j = 0; j < components.Length; j++)
                {
                    if (components[j] != null && components[j].GetInstanceID() == componentKuns[i].instanceID)
                    {
                        component = components[j];
                        break;
                    }
                }

                if (component == null)
                {
                    UnityChoseKun.LogWarning("component == null");
                    continue;
                }
                componentKuns[i].WriteBack(component);
                componentKuns[i].dirty = false;
            }

            dirty = false;
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public void GetAllTextureInScene()
        {
            #if UNITY_2019_1_OR_NEWER
            var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
            if (scene != null)
            {
                var components = new List <Renderer>();
                foreach (var go in scene.GetRootGameObjects())
                {
                    GetSComponentsInChildren <Renderer>(go, components);
                }
                foreach (var renderer in components)
                {
                    if (renderer.materials != null)
                    {
                        for (var i = 0; i < renderer.materials.Length; i++)
                        {
                            var material = renderer.materials[i];
                            if (material != null)
                            {
                                var shader = material.shader;
                                if (shader != null)
                                {
                                    var cnt = shader.GetPropertyCount();
                                    //Debug.Log(shader.name + " cnt " + cnt);
                                    for (var j = 0; j < cnt; j++)
                                    {
                                        var type = shader.GetPropertyType(j);
                                        //Debug.Log(type);
                                        if (type != UnityEngine.Rendering.ShaderPropertyType.Texture)
                                        {
                                            continue;
                                        }
                                        var nameId  = shader.GetPropertyNameId(j);
                                        var texture = material.GetTexture(nameId);
                                        //Debug.Log("nameId:" + nameId);

                                        if (texture != null)
                                        {
                                            if (textureDict.ContainsKey(texture.GetInstanceID()))
                                            {
                                                continue;
                                            }
                                            textureDict.Add(texture.GetInstanceID(), texture);
                                        }
                                        else
                                        {
                                            //Debug.Log("texture == null");
                                        }
                                    }
                                }
                                else
                                {
                                    UnityChoseKun.LogWarning("shader == null");
                                }
                            }
                            else
                            {
                                UnityChoseKun.LogWarning("material == null");
                            }
                        }
                    }
                }
            }
            else
            {
                UnityChoseKun.LogWarning("scene == null");
            }
            #endif
        }