Ejemplo n.º 1
0
    public static qb_Template LoadFromEditorPrefs(int slotIndex)
    {
        string prefix = "qbSettings_" + slotIndex.ToString() + "-";

        if (!EditorPrefs.HasKey(prefix))
        {
            return(null);
        }

        qb_Template template = new qb_Template();

        template.brushName   = EditorPrefs.GetString(prefix + "BrushName", template.brushName);
        template.lastKnownAs = EditorPrefs.GetString(prefix + "LastKnownAs", template.lastKnownAs);
        #region Brush Settings Vars
        template.brushRadius     = EditorPrefs.GetFloat(prefix + "BrushRadius", template.brushRadius);                      //(float) propertyTable["BrushRadius"];
        template.brushRadiusMin  = EditorPrefs.GetFloat(prefix + "BrushRadiusMin", template.brushRadiusMin);                //(float) propertyTable["BrushRadiusMin"];
        template.brushRadiusMax  = EditorPrefs.GetFloat(prefix + "BrushRadiusMax", template.brushRadiusMax);                //(float) propertyTable["BrushRadiusMax"];
        template.brushSpacing    = EditorPrefs.GetFloat(prefix + "BrushSpacing", template.brushSpacing);                    //(float) propertyTable["BrushSpacing"];
        template.brushSpacingMin = EditorPrefs.GetFloat(prefix + "BrushSpacingMin", template.brushSpacingMin);              //(float) propertyTable["BrushSpacingMin"];
        template.brushSpacingMax = EditorPrefs.GetFloat(prefix + "BrushSpacingMax", template.brushSpacingMax);              //(float) propertyTable["BrushSpacingMax"];
        template.scatterRadius   = EditorPrefs.GetFloat(prefix + "ScatterRadius", template.scatterRadius);                  //(float) propertyTable["ScatterRadius"];
        #endregion

        #region Rotation Settings Vars

        template.alignToNormal      = EditorPrefs.GetBool(prefix + "AlignToNormal", template.alignToNormal);                   //(bool) propertyTable["AlignToNormal"];
        template.flipNormalAlign    = EditorPrefs.GetBool(prefix + "FlipNormalAlign", template.flipNormalAlign);               //(bool) propertyTable["FlipNormalAlign"];
        template.alignToStroke      = EditorPrefs.GetBool(prefix + "AlignToStroke", template.alignToStroke);                   //(bool) propertyTable["AlignToStroke"];
        template.flipStrokeAlign    = EditorPrefs.GetBool(prefix + "FlipStrokeAlign", template.flipStrokeAlign);               //(bool) propertyTable["FlipStrokeAlign"];
        template.rotationRangeMin.x = EditorPrefs.GetFloat(prefix + "RotationRangeMinX", template.rotationRangeMin.x);         //(float) propertyTable["RotationRangeMinX"];
        template.rotationRangeMin.y = EditorPrefs.GetFloat(prefix + "RotationRangeMinY", template.rotationRangeMin.y);         //(float) propertyTable["RotationRangeMinY"];
        template.rotationRangeMin.z = EditorPrefs.GetFloat(prefix + "RotationRangeMinZ", template.rotationRangeMin.z);         //(float) propertyTable["RotationRangeMinZ"];
        template.rotationRangeMax.x = EditorPrefs.GetFloat(prefix + "RotationRangeMaxX", template.rotationRangeMax.x);         //(float) propertyTable["RotationRangeMaxX"];
        template.rotationRangeMax.y = EditorPrefs.GetFloat(prefix + "RotationRangeMaxY", template.rotationRangeMax.y);         //(float) propertyTable["RotationRangeMaxY"];
        template.rotationRangeMax.z = EditorPrefs.GetFloat(prefix + "RotationRangeMaxZ", template.rotationRangeMax.z);         //(float) propertyTable["RotationRangeMaxZ"];
        #endregion

        #region Position Settings Vars
        template.positionOffset.x = EditorPrefs.GetFloat(prefix + "PositionOffsetX", template.positionOffset.x);                     //(float) propertyTable["PositionOffsetX"];
        template.positionOffset.y = EditorPrefs.GetFloat(prefix + "PositionOffsetY", template.positionOffset.y);                     //(float) propertyTable["PositionOffsetY"];
        template.positionOffset.z = EditorPrefs.GetFloat(prefix + "PositionOffsetZ", template.positionOffset.z);                     //(float) propertyTable["PositionOffsetZ"];
        #endregion

        #region Scale Settings Vars
        template.scaleAbsolute = EditorPrefs.GetBool(prefix + "ScaleAbsolute", template.scaleAbsolute);

        //The minimum and maximum possible scale
        template.scaleMin = EditorPrefs.GetFloat(prefix + "ScaleMin", template.scaleMin);                                    //(float) propertyTable["ScaleMin"];
        template.scaleMax = EditorPrefs.GetFloat(prefix + "ScaleMax", template.scaleMax);                                    //(float) propertyTable["ScaleMax"];
        //The minimum and maximum current scale range setting
        template.scaleRandMin.x      = EditorPrefs.GetFloat(prefix + "ScaleRandMinX", template.scaleRandMin.x);              //(float) propertyTable["ScaleRandMinX"];
        template.scaleRandMin.y      = EditorPrefs.GetFloat(prefix + "ScaleRandMinY", template.scaleRandMin.y);              //(float) propertyTable["ScaleRandMinY"];
        template.scaleRandMin.z      = EditorPrefs.GetFloat(prefix + "ScaleRandMinZ", template.scaleRandMin.z);              //(float) propertyTable["ScaleRandMinZ"];
        template.scaleRandMax.x      = EditorPrefs.GetFloat(prefix + "ScaleRandMaxX", template.scaleRandMax.x);              //(float) propertyTable["ScaleRandMaxX"];
        template.scaleRandMax.y      = EditorPrefs.GetFloat(prefix + "ScaleRandMaxY", template.scaleRandMax.y);              //(float) propertyTable["ScaleRandMaxY"];
        template.scaleRandMax.z      = EditorPrefs.GetFloat(prefix + "ScaleRandMaxZ", template.scaleRandMax.z);              //(float) propertyTable["ScaleRandMaxZ"];
        template.scaleRandMinUniform = EditorPrefs.GetFloat(prefix + "ScaleRandMinUniform", template.scaleRandMinUniform);   //(float) propertyTable["ScaleRandMinUniform"];
        template.scaleRandMaxUniform = EditorPrefs.GetFloat(prefix + "ScaleRandMaxUniform", template.scaleRandMaxUniform);   //(float) propertyTable["ScaleRandMaxUniform"];
        template.scaleUniform        = EditorPrefs.GetBool(prefix + "ScaleUniform", template.scaleUniform);                  //(bool) propertyTable["ScaleUniform"];
        #endregion

        #region Sorting Vars
        //Selection
        template.paintToSelection = EditorPrefs.GetBool(prefix + "PaintToSelection", template.paintToSelection);        //(bool) propertyTable["PaintToSelection"];
        //Layers
        template.paintToLayer = EditorPrefs.GetBool(prefix + "PaintToLayer", template.paintToLayer);                    //(bool) propertyTable["PaintToLayer"];
        template.layerIndex   = EditorPrefs.GetInt(prefix + "LayerIndex", template.layerIndex);                         //(int) propertyTable["LayerIndex"];
        template.groupObjects = EditorPrefs.GetBool(prefix + "GroupObjects", template.groupObjects);
        //template.groupIndex =			EditorPrefs.GetInt(prefix + "GroupIndex",template.groupIndex);
        template.groupName = EditorPrefs.GetString(prefix + "GroupName", template.groupName);
        #endregion

        #region Eraser Vars
        template.eraseByGroup    = EditorPrefs.GetBool(prefix + "EraseByGroup", template.eraseByGroup);                      //(bool) propertyTable["EraseByGroup"];
        template.eraseBySelected = EditorPrefs.GetBool(prefix + "EraseBySelected", template.eraseBySelected);                //(bool) propertyTable["EraseBySelected"];
        #endregion


        #region Repopulate the Prefab List
        string            prefabGroupString = EditorPrefs.GetString(prefix + "PrefabGUIDList", string.Empty);   // (string) propertyTable["PrefabGUIDList"];
        qb_PrefabObject[] prefabGroup       = new qb_PrefabObject[0];

        string[] prefabStringList            = new string[0];
        List <UnityEngine.Object> newPrefabs = new List <UnityEngine.Object>();

        if (prefabGroupString != string.Empty)
        {
            //first clear out any items that are in the prefab list now
            prefabGroup = new qb_PrefabObject[0];
            //then retreive and split the saved prefab guids into a list
            prefabStringList = prefabGroupString.Split('/');            //string;
        }

        foreach (string prefabString in prefabStringList)
        {
            if (prefabString == string.Empty)
            {
                continue;
            }

            int    splitIndex   = prefabString.IndexOf("-");
            string GUIDstring   = string.Empty;
            string weightString = string.Empty;

            if (prefabString.Contains("-"))
            {
                GUIDstring   = prefabString.Substring(0, splitIndex);
                weightString = prefabString.Substring(splitIndex + 1);
            }

            else
            {
                GUIDstring = prefabString;
            }

            if (GUIDstring == string.Empty)
            {
                continue;
            }

            float itemWeight = 1f;
            if (weightString != null && weightString != string.Empty)
            {
                itemWeight = System.Convert.ToSingle(weightString);
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(GUIDstring);
            Object item      = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

            if (item != null)
            {
                newPrefabs.Add(item);

                ArrayUtility.Add(ref prefabGroup, new qb_PrefabObject(item, itemWeight));
            }
        }

        /*
         * if(newPrefabs.Count > 0)
         * {
         *      foreach(UnityEngine.Object newPrefab in newPrefabs)
         *      {
         *              ArrayUtility.Add(ref prefabGroup,new qb_PrefabObject(newPrefab,1f));
         *      }
         * }
         */
        template.prefabGroup = prefabGroup;
        #endregion


        #region Maintenance Vars
        template.dirty = EditorPrefs.GetBool(prefix + "Dirty", template.dirty);
        template.live  = true;
        #endregion


        #region LiveVars

        template.active = EditorPrefs.GetBool(prefix + "Active", false);

        template.selectedPrefabIndex = EditorPrefs.GetInt(prefix + "SelectedPrefabIndex", -1);

        #endregion

        return(template);
    }
Ejemplo n.º 2
0
    public static qb_Template LoadFromDisk(string fileLocationString)
    {
        //brush properties pulled from disk and re-assembled in new qb_Brush class instance
        BinaryFormatter formatter = new BinaryFormatter();
        Stream          stream    = new FileStream(fileLocationString, FileMode.Open, FileAccess.Read, FileShare.Read);

        Hashtable propertyTable = (Hashtable)formatter.Deserialize(stream);

        stream.Close();

        qb_Template template = new qb_Template();        //ScriptableObject.CreateInstance<qb_Template>();//new qb_Template();

        template.brushName = (string)GetProperty <string>(ref propertyTable, "BrushName", template.brushName);

        template.lastKnownAs = (string)GetProperty <string>(ref propertyTable, "LastKnownAs", template.lastKnownAs);
        #region Brush Settings Vars
        template.brushRadius = (float)GetProperty <float>(ref propertyTable, "BrushRadius", template.brushRadius);

        template.brushRadiusMin = (float)GetProperty <float>(ref propertyTable, "BrushRadiusMin", template.brushRadiusMin);

        template.brushRadiusMax = (float)GetProperty <float>(ref propertyTable, "BrushRadiusMax", template.brushRadiusMax);

        template.brushSpacing = (float)GetProperty <float>(ref propertyTable, "BrushSpacing", template.brushSpacing);

        template.brushSpacingMin = (float)GetProperty <float>(ref propertyTable, "BrushSpacingMin", template.brushSpacingMin);

        template.brushSpacingMax = (float)GetProperty <float>(ref propertyTable, "BrushSpacingMax", template.brushSpacingMax);

        template.scatterRadius = (float)GetProperty <float>(ref propertyTable, "ScatterRadius", template.scatterRadius);
        #endregion

        #region Rotation Settings Vars
        template.alignToNormal = (bool)GetProperty <bool>(ref propertyTable, "AlignToNormal", template.alignToNormal);

        template.flipNormalAlign = (bool)GetProperty <bool>(ref propertyTable, "FlipNormalAlign", template.flipNormalAlign);

        template.alignToStroke = (bool)GetProperty <bool>(ref propertyTable, "AlignToStroke", template.alignToStroke);

        template.flipStrokeAlign = (bool)GetProperty <bool>(ref propertyTable, "FlipStrokeAlign", template.flipStrokeAlign);

        template.rotationRangeMin.x = (float)GetProperty <float>(ref propertyTable, "RotationRangeMinX", template.rotationRangeMin.x);
        template.rotationRangeMin.y = (float)GetProperty <float>(ref propertyTable, "RotationRangeMinY", template.rotationRangeMin.y);
        template.rotationRangeMin.z = (float)GetProperty <float>(ref propertyTable, "RotationRangeMinZ", template.rotationRangeMin.z);

        template.rotationRangeMax.x = (float)GetProperty <float>(ref propertyTable, "RotationRangeMaxX", template.rotationRangeMax.x);
        template.rotationRangeMax.y = (float)GetProperty <float>(ref propertyTable, "RotationRangeMaxY", template.rotationRangeMax.y);
        template.rotationRangeMax.z = (float)GetProperty <float>(ref propertyTable, "RotationRangeMaxZ", template.rotationRangeMax.z);
        #endregion

        #region Position Settings Vars
        template.positionOffset.x = (float)GetProperty <float>(ref propertyTable, "PositionOffsetX", template.positionOffset.x);
        template.positionOffset.y = (float)GetProperty <float>(ref propertyTable, "PositionOffsetY", template.positionOffset.y);
        template.positionOffset.z = (float)GetProperty <float>(ref propertyTable, "PositionOffsetZ", template.positionOffset.z);
        #endregion

        #region Scale Settings Vars
        template.scaleAbsolute = (bool)GetProperty <bool>(ref propertyTable, "ScaleAbsolute", template.scaleAbsolute);

        //The minimum and maximum possible scale
        template.scaleMin = (float)GetProperty <float>(ref propertyTable, "ScaleMin", template.scaleMin);
        template.scaleMax = (float)GetProperty <float>(ref propertyTable, "ScaleMax", template.scaleMax);

        //The minimum and maximum current scale range setting
        template.scaleRandMin.x = (float)GetProperty <float>(ref propertyTable, "ScaleRandMinX", template.scaleRandMin.x);
        template.scaleRandMin.y = (float)GetProperty <float>(ref propertyTable, "ScaleRandMinY", template.scaleRandMin.y);
        template.scaleRandMin.z = (float)GetProperty <float>(ref propertyTable, "ScaleRandMinZ", template.scaleRandMin.z);

        template.scaleRandMax.x = (float)GetProperty <float>(ref propertyTable, "ScaleRandMaxX", template.scaleRandMax.x);
        template.scaleRandMax.y = (float)GetProperty <float>(ref propertyTable, "ScaleRandMaxY", template.scaleRandMax.y);
        template.scaleRandMax.z = (float)GetProperty <float>(ref propertyTable, "ScaleRandMaxZ", template.scaleRandMax.z);

        template.scaleRandMinUniform = (float)GetProperty <float>(ref propertyTable, "ScaleRandMinUniform", template.scaleRandMinUniform);
        template.scaleRandMaxUniform = (float)GetProperty <float>(ref propertyTable, "ScaleRandMaxUniform", template.scaleRandMaxUniform);

        template.scaleUniform = (bool)GetProperty <bool>(ref propertyTable, "ScaleUniform", template.scaleUniform);
        #endregion

        #region Sorting Vars
        //Selection
        template.paintToSelection = (bool)GetProperty <bool>(ref propertyTable, "PaintToSelection", template.paintToSelection);

        //Layers
        template.paintToLayer = (bool)GetProperty <bool>(ref propertyTable, "PaintToLayer", template.paintToLayer);

        template.layerIndex = (int)GetProperty <int>(ref propertyTable, "LayerIndex", template.layerIndex);

        template.groupObjects = (bool)GetProperty <bool>(ref propertyTable, "GroupObjects", template.groupObjects);

        //template.groupIndex =		(int) GetProperty<int>(ref propertyTable,"GroupIndex",template.groupIndex);
        template.groupName = (string)GetProperty <string>(ref propertyTable, "GroupName", template.groupName);
        #endregion

        #region Eraser Vars
        template.eraseByGroup    = (bool)GetProperty <bool>(ref propertyTable, "EraseByGroup", template.eraseByGroup);
        template.eraseBySelected = (bool)GetProperty <bool>(ref propertyTable, "EraseBySelected", template.eraseBySelected);
        #endregion

        #region Repopulate the Prefab List
        string            prefabGroupString = (string)GetProperty <string>(ref propertyTable, "PrefabGUIDList", string.Empty);
        qb_PrefabObject[] prefabGroup       = new qb_PrefabObject[0];

        string[] prefabStringList            = new string[0];
        List <UnityEngine.Object> newPrefabs = new List <UnityEngine.Object>();

        if (prefabGroupString != string.Empty)
        {
            //first clear out any items that are in the prefab list now
            prefabGroup = new qb_PrefabObject[0];
            //then retreive and split the saved prefab guids into a list
            prefabStringList = prefabGroupString.Split('/');            //string;
        }

        foreach (string prefabString in prefabStringList)
        {
            if (prefabString == string.Empty)
            {
                continue;
            }

            int    splitIndex   = prefabString.IndexOf("-");
            string GUIDstring   = string.Empty;
            string weightString = string.Empty;

            if (prefabString.Contains("-"))
            {
                GUIDstring   = prefabString.Substring(0, splitIndex);
                weightString = prefabString.Substring(splitIndex + 1);
            }

            else
            {
                GUIDstring = prefabString;
            }

            if (GUIDstring == string.Empty)
            {
                continue;
            }

            float itemWeight = 1f;
            if (weightString != null && weightString != string.Empty)
            {
                itemWeight = System.Convert.ToSingle(weightString);
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(GUIDstring);
            Object item      = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

            if (item != null)
            {
                newPrefabs.Add(item);

                ArrayUtility.Add(ref prefabGroup, new qb_PrefabObject(item, itemWeight));
            }
        }

        /*
         * if(newPrefabs.Count > 0)
         * {
         *      foreach(UnityEngine.Object newPrefab in newPrefabs)
         *      {
         *              ArrayUtility.Add(ref prefabGroup,new qb_PrefabObject(newPrefab,1f));
         *      }
         * }
         */
        template.prefabGroup = prefabGroup;
        #endregion

        template.live = true;

        return(template);
    }