Esempio n. 1
0
        public static void Rollback()
        {
            HB hb = GameObject.FindObjectOfType <HB>();

            if (hb != null)
            {
                hb.Internal_Rollback(true);
                GameObject.DestroyImmediate(hb.gameObject);
            }
        }
Esempio n. 2
0
        private void Configure()
        {
            string path = Application.dataPath + "/Battlehub/HorizonBending/Shaders/_Templates";

            if (!Directory.Exists(path))
            {
                Debug.LogError("Unable to configure. Required " + path + " folder is missing. Try reimport");
                return;
            }

            string      properties;
            string      feature;
            string      hbst;
            string      hbstm;
            BendingMode bendingMode = BendingMode._HB_XZ_YUP;

            if (m_profile == 0)
            {
                if (m_worldUpAxis == 0)   //X
                {
                    if (m_bendAxis == 0)
                    {
                        feature     = "_HB_YZ_XUP 1";
                        bendingMode = BendingMode._HB_YZ_XUP;
                    }
                    else if (m_bendAxis == 1)
                    {
                        feature     = "_HB_Y_XUP 1";
                        bendingMode = BendingMode._HB_Y_XUP;
                    }
                    else
                    {
                        feature     = "_HB_Z_XUP 1";
                        bendingMode = BendingMode._HB_Z_XUP;
                    }
                }
                else if (m_worldUpAxis == 1) //Y
                {
                    if (m_bendAxis == 0)
                    {
                        feature     = "_HB_XZ_YUP 1";
                        bendingMode = BendingMode._HB_XZ_YUP;
                    }
                    else if (m_bendAxis == 1)
                    {
                        feature     = "_HB_X_YUP 1";
                        bendingMode = BendingMode._HB_X_YUP;
                    }
                    else
                    {
                        feature     = "_HB_Z_YUP 1";
                        bendingMode = BendingMode._HB_Z_YUP;
                    }
                }
                else //Z
                {
                    if (m_bendAxis == 0)
                    {
                        feature     = "_HB_XY_ZUP 1";
                        bendingMode = BendingMode._HB_XY_ZUP;
                    }
                    else if (m_bendAxis == 1)
                    {
                        feature     = "_HB_X_ZUP 1";
                        bendingMode = BendingMode._HB_X_ZUP;
                    }
                    else
                    {
                        feature     = "_HB_Y_ZUP 1";
                        bendingMode = BendingMode._HB_Y_ZUP;
                    }
                }

                properties = string.Empty;
                hbst       = "#define " + feature;
                hbstm      = "#define " + feature;
            }
            else
            {
                feature    = "#pragma multi_compile _HB_YZ_XUP _HB_Y_XUP _HB_Z_XUP _HB_XZ_YUP _HB_X_YUP _HB_Z_YUP _HB_XY_ZUP _HB_X_ZUP _HB_Y_ZUP";
                hbst       = feature;
                hbstm      = feature;
                properties = "XZ_YUp, X_YUp, Z_YUp, YZ_XUp, Y_XUp, Z_XUp, XY_ZUp, X_ZUp, Y_ZUp";
            }

            properties = string.Format("[KeywordEnum({0})] _HB(\"Bending Mode\", Float) = 0", properties);
            bool importShaders = bendingMode != Internal_BendingModePrefs;

            if (!importShaders)
            {
                importShaders = !ShadersExist(path, "hbst") || !ShadersExist(path, "hbstm");
            }
            if (importShaders)
            {
                CreateShaders(m_profile, path, properties, hbst, "hbst");
                CreateShaders(m_profile, path, properties, hbstm, "hbstm");
            }
            HB hb = GameObject.FindObjectOfType <HB>();

            if (hb != null)
            {
                hb.Internal_Rollback(true);
                GameObject.DestroyImmediate(hb.gameObject);
            }

            GameObject hbGO = StorageHelper.InstantiatePrefab("HB.prefab");

            hb                        = hbGO.GetComponent <HB>();
            hb.BendingMode            = bendingMode;
            Internal_BendingModePrefs = bendingMode;
            if (m_profile == 0)
            {
                Internal_AllowChangeBendingMode = false;
            }
            else
            {
                Internal_AllowChangeBendingMode = true;
            }
            StorageHelper.CreatePrefab(hbGO.name + ".prefab", hbGO);
            DestroyImmediate(hbGO);
            if (importShaders)
            {
                AssetDatabase.ImportAsset("Assets/Battlehub/HorizonBending/Shaders/", ImportAssetOptions.ImportRecursive);
            }

            EditorPrefs.SetBool("HBConfigured", true);
        }
Esempio n. 3
0
        public static void Apply()
        {
            HB hb = GameObject.FindObjectOfType <HB>();

            bool        copySettings           = false;
            float       curvature              = 0.0f;
            float       flatten                = 0.0f;
            float       horizonXOffset         = 0.0f;
            float       horizonYOffset         = 0.0f;
            float       horizonZOffset         = 0.0f;
            BendingMode bendingMode            = BendingMode._HB_OFF;
            float       raycastStride          = 0.0f;
            float       fixBoundsRadius        = 0.0f;
            float       fixFieldOfView         = 0.0f;
            float       fixOrthographicSize    = 0.0f;
            bool        attachToCameraInEditor = false;
            bool        lockMaterials          = false;

            Material[] materials               = new Material[0];
            Shader[]   integratedShaders       = new Shader[0];
            Camera     fixLightPositionsCamera = null;

            GameObject[] excludeGameObjects = new GameObject[0];
            if (hb != null)
            {
                copySettings            = true;
                curvature               = hb.Curvature;
                flatten                 = hb.Flatten;
                horizonXOffset          = hb.HorizonXOffset;
                horizonYOffset          = hb.HorizonYOffset;
                horizonZOffset          = hb.HorizonZOffset;
                bendingMode             = hb.BendingMode;
                raycastStride           = hb.RaycastStride;
                fixBoundsRadius         = hb.FixBoundsRadius;
                fixFieldOfView          = hb.FixFieldOfView;
                fixOrthographicSize     = hb.FixOrthographicSize;
                fixLightPositionsCamera = hb.FixLightsPositionCamera;
                attachToCameraInEditor  = hb.AttachToCamera;
                lockMaterials           = hb.LockMaterials;
                materials               = hb.Materials;
                integratedShaders       = hb.CustomShaders;
                excludeGameObjects      = hb.ExcludeGameObjects;

                hb.Internal_Rollback(false);
                GameObject.DestroyImmediate(hb.gameObject);
            }

            GameObject hbGO = StorageHelper.InstantiatePrefab("HB.prefab");

            PrefabUtility.DisconnectPrefabInstance(hbGO);
            hb = hbGO.GetComponent <HB>();
            if (copySettings)
            {
                hb.Curvature               = curvature;
                hb.Flatten                 = flatten;
                hb.HorizonXOffset          = horizonXOffset;
                hb.HorizonYOffset          = horizonYOffset;
                hb.HorizonZOffset          = horizonZOffset;
                hb.BendingMode             = bendingMode;
                hb.RaycastStride           = raycastStride;
                hb.FixBoundsRadius         = fixBoundsRadius;
                hb.FixFieldOfView          = fixFieldOfView;
                hb.FixOrthographicSize     = fixOrthographicSize;
                hb.FixLightsPositionCamera = fixLightPositionsCamera;
                hb.AttachToCamera          = attachToCameraInEditor;
                hb.LockMaterials           = lockMaterials;
                hb.Materials               = materials;
                hb.CustomShaders           = integratedShaders;
                hb.ExcludeGameObjects      = excludeGameObjects;
            }
            else
            {
                hb.FixFieldOfView      = 0.0f;
                hb.FixOrthographicSize = 0.0f;
            }

            hb.Internal_Apply();
            Selection.activeObject = hb.gameObject;
        }