Ejemplo n.º 1
0
        private void CheckAmbientAndCorrection()
        {
            if (_editor == null)
            {
                return;
            }
            if (!_editor._isAmbientCorrectionOption)
            {
                //Ambient 보정 옵션이 False이면 처리를 안함
                return;
            }

            //현재 Ambient 색상과 모드를 확인하자
            UnityEngine.Rendering.AmbientMode ambientMode = RenderSettings.ambientMode;
            Color ambientColor = RenderSettings.ambientLight;

            if (ambientMode == UnityEngine.Rendering.AmbientMode.Flat &&
                ambientColor.r <= 0.001f &&
                ambientColor.g <= 0.001f &&
                ambientColor.b <= 0.001f)
            {
                //Ambient가 검은색이다.
                return;
            }
            //이전
            ////Ambient 색상을 바꿀 것인지 물어보자
            #region [미사용 코드]
            //int iBtn = EditorUtility.DisplayDialogComplex(
            //										_editor.GetText(TEXT.DLG_AmbientColorCorrection_Title),
            //										_editor.GetText(TEXT.DLG_AmbientColorCorrection_Body),
            //										_editor.GetText(TEXT.Okay),
            //										_editor.GetText(TEXT.DLG_AmbientColorCorrection_Ignore),
            //										_editor.GetText(TEXT.Cancel)
            //										);

            //if(iBtn == 0)
            //{
            //	//색상을 바꾸자
            //	MakeAmbientLightToBlack();
            //}
            //else if(iBtn == 1)
            //{
            //	//무시하자
            //	_editor._isAmbientCorrectionOption = false;
            //	_editor.SaveEditorPref();
            //}
            #endregion

            //조건문 추가 19.6.22 : 현재의 기본 Material Set이 Ambient Color 색상이 검은색을 필요로할 경우
            if (_targetPortrait != null)
            {
                apMaterialSet defaultMatSet = _targetPortrait.GetDefaultMaterialSet();
                if (defaultMatSet != null)
                {
                    if (!defaultMatSet._isNeedToSetBlackColoredAmbient)
                    {
                        //현재의 Default MatSet이 검은색을 필요로 하지 않는 경우
                        return;
                    }
                }
            }
            //이후 : 별도의 다이얼로그 표시
            apDialog_AmbientCorrection.ShowDialog(_editor, (int)position.x, (int)position.y);
        }
Ejemplo n.º 2
0
        // Bake
        //---------------------------------------------------
#if UNITY_EDITOR
        public void Bake(apTransform_Mesh srcMeshTransform, apPortrait portrait, bool isLinearSpace, int textureDataID, apMaterialLibrary materialLibrary)
        {
            Clear();

            //1. 기본 텍스쳐를 만든다.
            Texture2D mainTex = null;

            if (srcMeshTransform._mesh != null &&
                srcMeshTransform._mesh.LinkedTextureData != null)
            {
                mainTex = srcMeshTransform._mesh.LinkedTextureData._image;
            }

            if (mainTex == null)
            {
                return;
            }

            //2. Shader를 연결한다.
            Shader        targetShader = null;
            apMaterialSet srcMatSet    = null;

            apMaterialSet defaultMatSet = portrait.GetDefaultMaterialSet();
            apMaterialSet libraryMatSet = materialLibrary.Presets[0];            //<<Library의 첫번째 프리셋

            bool isClippedChild = srcMeshTransform._isClipping_Child;

            if (srcMeshTransform._isCustomShader)
            {
                //2-1. Custom Shader를 사용하는 경우
                targetShader = srcMeshTransform._customShader;
            }
            else
            {
                srcMatSet = srcMeshTransform._linkedMaterialSet;
                if (srcMatSet == null)
                {
                    srcMatSet = defaultMatSet;
                }

                if (srcMatSet == null)
                {
                    srcMatSet = libraryMatSet;
                }

                if (srcMatSet == null)
                {
                    return;
                }

                //조건에 맞는 Shader를 받아오자
                targetShader = srcMatSet.GetShader(srcMeshTransform._shaderType, isClippedChild, isLinearSpace);

                //만약 현재 Material Set에 Shader가 없다면, Default Shader에서 가져오자.
                if (targetShader == null)
                {
                    targetShader = defaultMatSet.GetShader(srcMeshTransform._shaderType, isClippedChild, isLinearSpace);
                }
            }

            if (targetShader == null)
            {
                //Shader가 없으면 Material Liabrary에서 가져오자
                targetShader = libraryMatSet.GetShader(srcMeshTransform._shaderType, isClippedChild, isLinearSpace);
            }


            if (targetShader == null || mainTex == null)
            {
                return;
            }

            // 일단 MainTex와 Shader를 연결하자
            _isBaked   = true;
            _mainTex   = mainTex;
            _textureID = textureDataID;
            _shader    = targetShader;

            //3. 프로퍼티
            List <Property_Float>   list_Float   = new List <Property_Float>();
            List <Property_Int>     list_Int     = new List <Property_Int>();
            List <Property_Vector>  list_Vector  = new List <Property_Vector>();
            List <Property_Texture> list_Texture = new List <Property_Texture>();
            List <Property_Color>   list_Color   = new List <Property_Color>();

            //테스트를 위해서 Material을 생성
            Material mat_Test = new Material(_shader);


            //3-1. 먼저 MaterialSet의 정보를 리스트로 저장한다.
            if (srcMatSet != null)
            {
                for (int iSrcProp = 0; iSrcProp < srcMatSet._propertySets.Count; iSrcProp++)
                {
                    apMaterialSet.PropertySet srcProp = srcMatSet._propertySets[iSrcProp];
                    if (srcProp._isReserved ||
                        !srcProp._isOptionEnabled)
                    {
                        continue;
                    }

                    if (string.Equals(srcProp._name, "_Color") ||
                        string.Equals(srcProp._name, "_MainTex") ||
                        string.Equals(srcProp._name, "_MaskTex") ||
                        string.Equals(srcProp._name, "_MaskScreenSpaceOffset") ||
                        string.IsNullOrEmpty(srcProp._name))
                    {
                        //이 값은 사용할 수 없다. Reserved임
                        continue;
                    }

                    //프로퍼티가 있는 경우에만
                    bool isHasProp = mat_Test.HasProperty(srcProp._name);
                    if (!isHasProp)
                    {
                        //없는 Property.
                        continue;
                    }


                    switch (srcProp._propType)
                    {
                    case apMaterialSet.SHADER_PROP_TYPE.Float:
                        AddProperty_Float(list_Float, srcProp._name, srcProp._value_Float);
                        break;

                    case apMaterialSet.SHADER_PROP_TYPE.Int:
                        AddProperty_Int(list_Int, srcProp._name, srcProp._value_Int);
                        break;

                    case apMaterialSet.SHADER_PROP_TYPE.Vector:
                        AddProperty_Vector(list_Vector, srcProp._name, srcProp._value_Vector);
                        break;

                    case apMaterialSet.SHADER_PROP_TYPE.Texture:
                        if (srcProp._isCommonTexture)
                        {
                            //공통 텍스쳐인 경우
                            AddProperty_Texture(list_Texture, srcProp._name, srcProp._value_CommonTexture);
                        }
                        else
                        {
                            //TextureData에 해당하는 정보가 있는지 확인하자.
                            //없어도 null값을 넣는다. (null로 초기화하고 싶을 때도 있겠징...)
                            apMaterialSet.PropertySet.ImageTexturePair imgTexPair = srcProp._imageTexturePairs.Find(delegate(apMaterialSet.PropertySet.ImageTexturePair a)
                            {
                                return(a._textureDataID == textureDataID);
                            });
                            if (imgTexPair != null)
                            {
                                AddProperty_Texture(list_Texture, srcProp._name, imgTexPair._textureAsset);
                            }
                            else
                            {
                                AddProperty_Texture(list_Texture, srcProp._name, null);
                            }
                        }
                        break;

                    case apMaterialSet.SHADER_PROP_TYPE.Color:
                        AddProperty_Color(list_Color, srcProp._name, srcProp._value_Color);
                        break;
                    }
                }
            }


            //3-2. MeshTransform의 속성에 Overwrite 설정이 있을 수도 있다.
            if (srcMeshTransform._customMaterialProperties != null &&
                srcMeshTransform._customMaterialProperties.Count > 0)
            {
                for (int iSrcProp = 0; iSrcProp < srcMeshTransform._customMaterialProperties.Count; iSrcProp++)
                {
                    apTransform_Mesh.CustomMaterialProperty srcProp = srcMeshTransform._customMaterialProperties[iSrcProp];
                    if (string.Equals(srcProp._name, "_Color") ||
                        string.Equals(srcProp._name, "_MainTex") ||
                        string.Equals(srcProp._name, "_MaskTex") ||
                        string.Equals(srcProp._name, "_MaskScreenSpaceOffset") ||
                        string.IsNullOrEmpty(srcProp._name))
                    {
                        //이 값은 사용할 수 없다. Reserved임
                        continue;
                    }

                    //프로퍼티가 있는 경우에만
                    bool isHasProp = mat_Test.HasProperty(srcProp._name);
                    if (!isHasProp)
                    {
                        //없는 Property.
                        continue;
                    }

                    //이름을 비교하여, 기존의 값이 있다면 덮어 씌우고, 없으면 새로 만들기
                    switch (srcProp._propType)
                    {
                    case apTransform_Mesh.CustomMaterialProperty.SHADER_PROP_TYPE.Float:
                        AddProperty_Float(list_Float, srcProp._name, srcProp._value_Float);
                        break;

                    case apTransform_Mesh.CustomMaterialProperty.SHADER_PROP_TYPE.Int:
                        AddProperty_Int(list_Int, srcProp._name, srcProp._value_Int);
                        break;

                    case apTransform_Mesh.CustomMaterialProperty.SHADER_PROP_TYPE.Vector:
                        AddProperty_Vector(list_Vector, srcProp._name, srcProp._value_Vector);
                        break;

                    case apTransform_Mesh.CustomMaterialProperty.SHADER_PROP_TYPE.Texture:
                        AddProperty_Texture(list_Texture, srcProp._name, srcProp._value_Texture);
                        break;

                    case apTransform_Mesh.CustomMaterialProperty.SHADER_PROP_TYPE.Color:
                        AddProperty_Color(list_Color, srcProp._name, srcProp._value_Color);
                        break;
                    }
                }
            }

            UnityEngine.Object.DestroyImmediate(mat_Test);


            //리스트의 값을 변수로 저장한다.
            if (list_Float.Count > 0)
            {
                //정렬부터
                list_Float.Sort(delegate(Property_Float a, Property_Float b)
                {
                    return(string.Compare(a._name, b._name));
                });

                //값 복사
                _props_Float = new Property_Float[list_Float.Count];
                for (int i = 0; i < list_Float.Count; i++)
                {
                    _props_Float[i] = list_Float[i];
                }
            }

            if (list_Int.Count > 0)
            {
                //정렬부터
                list_Int.Sort(delegate(Property_Int a, Property_Int b)
                {
                    return(string.Compare(a._name, b._name));
                });

                //값 복사
                _props_Int = new Property_Int[list_Int.Count];
                for (int i = 0; i < list_Int.Count; i++)
                {
                    _props_Int[i] = list_Int[i];
                }
            }

            if (list_Vector.Count > 0)
            {
                //정렬부터
                list_Vector.Sort(delegate(Property_Vector a, Property_Vector b)
                {
                    return(string.Compare(a._name, b._name));
                });

                //값 복사
                _props_Vector = new Property_Vector[list_Vector.Count];
                for (int i = 0; i < list_Vector.Count; i++)
                {
                    _props_Vector[i] = list_Vector[i];
                }
            }

            if (list_Texture.Count > 0)
            {
                //정렬부터
                list_Float.Sort(delegate(Property_Float a, Property_Float b)
                {
                    return(string.Compare(a._name, b._name));
                });

                //값 복사
                _props_Texture = new Property_Texture[list_Texture.Count];
                for (int i = 0; i < list_Texture.Count; i++)
                {
                    _props_Texture[i] = list_Texture[i];
                }
            }

            if (list_Color.Count > 0)
            {
                //정렬부터
                list_Float.Sort(delegate(Property_Float a, Property_Float b)
                {
                    return(string.Compare(a._name, b._name));
                });

                //값 복사
                _props_Color = new Property_Color[list_Color.Count];
                for (int i = 0; i < list_Color.Count; i++)
                {
                    _props_Color[i] = list_Color[i];
                }
            }
        }