Esempio n. 1
0
        public static void HBMode(BendingMode mode)
        {
            foreach (BendingMode disableMode in Enum.GetValues(typeof(BendingMode)))
            {
                Shader.DisableKeyword(disableMode.ToString());
            }

            Shader.EnableKeyword(mode.ToString());
        }
Esempio n. 2
0
 private void Start()
 {
     m_previousMode           = BendingMode;
     m_previosPosition        = transform.position;
     m_previousCurvature      = Curvature;
     m_previousFlatten        = Flatten;
     m_previousHorizonZOffset = HorizonZOffset;
     m_previousHorizonYOffset = HorizonYOffset;
     m_previousHorizonXOffset = HorizonXOffset;
     m_prevCameraTracking     = AttachToCamera;
     m_appliedRadius          = FixBoundsRadius;
 }
Esempio n. 3
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. 4
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;
        }
Esempio n. 5
0
        private void Update()
        {
            if (Application.isPlaying)
            {
                return;
            }

            bool positionChanged = false;

            if (m_previosPosition != transform.position)
            {
                positionChanged   = !AttachToCamera;
                m_previosPosition = transform.position;
            }

            if (RaycastStride < 0.01f)
            {
                RaycastStride = 0.01f;
            }

            if (m_previousRadius != FixBoundsRadius)
            {
                if (FixBoundsRadius < 0)
                {
                    FixBoundsRadius = 0;
                }

                m_previousRadius = FixBoundsRadius;
            }
            if (m_previousCurvature != Curvature)
            {
                HBUtils.HBCurvature(Curvature * CURVATURE_FACTOR);
                m_previousCurvature = Curvature;
            }

            if (m_previousFlatten != Flatten)
            {
                if (Flatten < 0)
                {
                    Flatten = 0;
                }
                HBUtils.HBFlatten(Flatten);
                m_previousFlatten = Flatten;
            }

            if (m_previousHorizonZOffset != HorizonZOffset || m_previousHorizonYOffset != HorizonYOffset || m_previousHorizonXOffset != HorizonXOffset || positionChanged)
            {
                if (AttachToCamera)
                {
                    HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset);
                }
                else
                {
                    HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset, transform);
                }

                m_previousHorizonZOffset = HorizonZOffset;
                m_previousHorizonYOffset = HorizonYOffset;
                m_previousHorizonXOffset = HorizonXOffset;
            }

            if (m_previousMode != BendingMode)
            {
                HBUtils.HBMode(BendingMode);
                m_previousMode = BendingMode;
            }

            if (m_prevCameraTracking != AttachToCamera)
            {
                if (AttachToCamera)
                {
                    HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset);
                }
                else
                {
                    HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset, transform);
                }

                m_prevCameraTracking = AttachToCamera;
            }
        }
Esempio n. 6
0
        public HBSettings(BendingMode bendingMode, float curvature = 0.0f, float flatten = 0.0f, float horizonXOffset = 0.0f, float horizonYOffset = 0.0f, float horizonZOffset = 0.0f, bool relativeToCamera = false)
        {
            BendingMode            = bendingMode;
            Curvature              = curvature;
            Flatten                = flatten;
            HorizonZOffset         = horizonZOffset;
            HorizonYOffset         = horizonYOffset;
            HorizonXOffset         = horizonXOffset;
            AttachToCameraInEditor = relativeToCamera;

            if (bendingMode == BendingMode._HB_XY_ZUP)
            {
                Mask     = new Vector3(1.0f, 1.0f, 0.0f);
                Gradient = new Vector3(1.0f, 0.0f, 0.0f);
                Up       = new Vector3(0.0f, 0.0f, 1.0f);
            }
            else if (bendingMode == BendingMode._HB_X_ZUP)
            {
                Mask     = new Vector3(1.0f, 1.0f, 0.0f);
                Gradient = new Vector3(0.0f, 1.0f, 0.0f);
                Up       = new Vector3(0.0f, 0.0f, 1.0f);
            }
            else if (bendingMode == BendingMode._HB_Y_ZUP)
            {
                Mask     = new Vector3(1.0f, 1.0f, 0.0f);
                Gradient = new Vector3(1.0f, 0.0f, 0.0f);
                Up       = new Vector3(0.0f, 0.0f, 1.0f);
            }
            else if (bendingMode == BendingMode._HB_XZ_YUP)
            {
                Mask     = new Vector3(1.0f, 0.0f, 1.0f);
                Gradient = new Vector3(1.0f, 0.0f, 0.0f);
                Up       = new Vector3(0.0f, 1.0f, 0.0f);
            }
            else if (bendingMode == BendingMode._HB_X_YUP)
            {
                Mask     = new Vector3(1.0f, 0.0f, 1.0f);
                Gradient = new Vector3(0.0f, 0.0f, 1.0f);
                Up       = new Vector3(0.0f, 1.0f, 0.0f);
            }
            else if (bendingMode == BendingMode._HB_Z_YUP)
            {
                Mask     = new Vector3(1.0f, 0.0f, 1.0f);
                Gradient = new Vector3(1.0f, 0.0f, 0.0f);
                Up       = new Vector3(0.0f, 1.0f, 0.0f);
            }
            else if (bendingMode == BendingMode._HB_YZ_XUP)
            {
                Mask     = new Vector3(0.0f, 1.0f, 1.0f);
                Gradient = new Vector3(0.0f, 1.0f, 0.0f);
                Up       = new Vector3(1.0f, 0.0f, 0.0f);
            }
            else if (bendingMode == BendingMode._HB_Y_XUP)
            {
                Mask     = new Vector3(0.0f, 1.0f, 1.0f);
                Gradient = new Vector3(0.0f, 0.0f, 1.0f);
                Up       = new Vector3(1.0f, 0.0f, 0.0f);
            }
            else if (bendingMode == BendingMode._HB_Z_XUP)
            {
                Mask     = new Vector3(0.0f, 1.0f, 1.0f);
                Gradient = new Vector3(0.0f, 1.0f, 0.0f);
                Up       = new Vector3(1.0f, 0.0f, 0.0f);
            }
            else
            {
                Mask     = new Vector3(0.0f, 0.0f, 0.0f);
                Gradient = new Vector3(0.0f, 0.0f, 0.0f);
                Up       = new Vector3(0.0f, 0.0f, 0.0f);
            }
        }