示例#1
0
    static qb_Template[] GetSavedBrushes(string directory)
    {
        string[]      directories = GetTemplateFileDirectories(directory);
        qb_Template[] brushes     = new qb_Template[directories.Length];

        for (int i = 0; i < directories.Length; i++)
        {
            qb_Template brush = LoadFromDisk(directories[i]);
            brushes[i] = brush;
        }

        return(brushes);
    }
示例#2
0
    public static void SaveToDisk(qb_Template template, string directory)     // Save the current brush to memory
    {
        string fileName = directory + "/Templates/" + template.brushName + ".qbt";

        Stream stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
        //Debug.Log("SavingTemplate");
        Hashtable propertyTable = CreatePropertyTable(template);

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Serialize(stream, propertyTable);

        stream.Close();
    }
示例#3
0
    public static void SaveToEditorPrefs(int slotIndex, qb_Template template)
    {
        string prefix = "qbSettings_" + slotIndex.ToString() + "-";

        EditorPrefs.SetString(prefix, template.brushName);

        EditorPrefs.SetString(prefix + "BrushName", template.brushName);

        EditorPrefs.SetString(prefix + "LastKnownAs", template.lastKnownAs);

        #region Brush Settings Vars
        EditorPrefs.SetFloat(prefix + "BrushRadius", template.brushRadius);

        EditorPrefs.SetFloat(prefix + "BrushRadiusMin", template.brushRadiusMin);

        EditorPrefs.SetFloat(prefix + "BrushRadiusMax", template.brushRadiusMax);

        EditorPrefs.SetFloat(prefix + "BrushSpacing", template.brushSpacing);

        EditorPrefs.SetFloat(prefix + "BrushSpacingMin", template.brushSpacingMin);

        EditorPrefs.SetFloat(prefix + "BrushSpacingMax", template.brushSpacingMax);

        EditorPrefs.SetFloat(prefix + "ScatterRadius", template.scatterRadius);
        #endregion

        #region Rotation Settings Vars
        EditorPrefs.SetBool(prefix + "AlignToNormal", template.alignToNormal);

        EditorPrefs.SetBool(prefix + "FlipNormalAlign", template.flipNormalAlign);

        EditorPrefs.SetBool(prefix + "AlignToStroke", template.alignToStroke);

        EditorPrefs.SetBool(prefix + "FlipStrokeAlign", template.flipStrokeAlign);

        EditorPrefs.SetFloat(prefix + "RotationRangeMinX", template.rotationRangeMin.x);
        EditorPrefs.SetFloat(prefix + "RotationRangeMinY", template.rotationRangeMin.y);
        EditorPrefs.SetFloat(prefix + "RotationRangeMinZ", template.rotationRangeMin.z);

        EditorPrefs.SetFloat(prefix + "RotationRangeMaxX", template.rotationRangeMax.x);
        EditorPrefs.SetFloat(prefix + "RotationRangeMaxY", template.rotationRangeMax.y);
        EditorPrefs.SetFloat(prefix + "RotationRangeMaxZ", template.rotationRangeMax.z);
        #endregion

        #region Position Settings Vars
        EditorPrefs.SetFloat(prefix + "PositionOffsetX", template.positionOffset.x);
        EditorPrefs.SetFloat(prefix + "PositionOffsetY", template.positionOffset.y);
        EditorPrefs.SetFloat(prefix + "PositionOffsetZ", template.positionOffset.z);
        #endregion

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

        //The minimum and maximum possible scale
        EditorPrefs.SetFloat(prefix + "ScaleMin", template.scaleMin);

        EditorPrefs.SetFloat(prefix + "ScaleMax", template.scaleMax);

        //The minimum and maximum current scale range setting
        EditorPrefs.SetFloat(prefix + "ScaleRandMinX", template.scaleRandMin.x);
        EditorPrefs.SetFloat(prefix + "ScaleRandMinY", template.scaleRandMin.y);
        EditorPrefs.SetFloat(prefix + "ScaleRandMinZ", template.scaleRandMin.z);

        EditorPrefs.SetFloat(prefix + "ScaleRandMaxX", template.scaleRandMax.x);
        EditorPrefs.SetFloat(prefix + "ScaleRandMaxY", template.scaleRandMax.y);
        EditorPrefs.SetFloat(prefix + "ScaleRandMaxZ", template.scaleRandMax.z);

        EditorPrefs.SetFloat(prefix + "ScaleRandMinUniform", template.scaleRandMinUniform);

        EditorPrefs.SetFloat(prefix + "ScaleRandMaxUniform", template.scaleRandMaxUniform);

        EditorPrefs.SetBool(prefix + "ScaleUniform", template.scaleUniform);
        #endregion

        #region Sorting Vars
        //Selection
        EditorPrefs.SetBool(prefix + "PaintToSelection", template.paintToSelection);

        //Layers
        EditorPrefs.SetBool(prefix + "PaintToLayer", template.paintToLayer);

        EditorPrefs.SetInt(prefix + "LayerIndex", template.layerIndex);

        EditorPrefs.SetBool(prefix + "GroupObjects", template.groupObjects);

        //EditorPrefs.SetInt(prefix + "GroupIndex",template.groupIndex);
        EditorPrefs.SetString(prefix + "GroupName", template.groupName);
        #endregion

        #region Eraser Vars
        EditorPrefs.SetBool(prefix + "EraseByGroup", template.eraseByGroup);
        EditorPrefs.SetBool(prefix + "EraseBySelected", template.eraseBySelected);
        #endregion

        //New Prefab Save
        string prefabGroupString = string.Empty;

        for (int i = 0; i < template.prefabGroup.Length; i++)
        {
            prefabGroupString += "/" + AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(template.prefabGroup[i].prefab)) + "-" + template.prefabGroup[i].weight.ToString();
            //prefabGroupString += "/" + AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(template.prefabGroup[i].prefab)) + "-" + template.prefabGroup[i].weight.ToString() + ">" + template.prefabGroup[i];
        }

        EditorPrefs.SetString(prefix + "PrefabGUIDList", prefabGroupString);

        #region Maintenance Vars
        EditorPrefs.SetBool(prefix + "Dirty", template.dirty);
        #endregion

        //return propertyTable;
        #region LiveVars

        EditorPrefs.SetBool(prefix + "Active", template.active);

        EditorPrefs.SetInt(prefix + "SelectedPrefabIndex", template.selectedPrefabIndex);

        #endregion
    }
示例#4
0
    static Hashtable CreatePropertyTable(qb_Template template)          //converts brush class to a hash table of values
    {
        Hashtable propertyTable = new Hashtable();

        propertyTable.Add("BrushName", template.brushName);

        propertyTable.Add("LastKnownAs", template.lastKnownAs);

        #region Brush Settings Vars
        propertyTable.Add("BrushRadius", template.brushRadius);

        propertyTable.Add("BrushRadiusMin", template.brushRadiusMin);

        propertyTable.Add("BrushRadiusMax", template.brushRadiusMax);

        propertyTable.Add("BrushSpacing", template.brushSpacing);

        propertyTable.Add("BrushSpacingMin", template.brushSpacingMin);

        propertyTable.Add("BrushSpacingMax", template.brushSpacingMax);

        propertyTable.Add("ScatterRadius", template.scatterRadius);
        #endregion

        #region Rotation Settings Vars
        propertyTable.Add("AlignToNormal", template.alignToNormal);

        propertyTable.Add("FlipNormalAlign", template.flipNormalAlign);

        propertyTable.Add("AlignToStroke", template.alignToStroke);

        propertyTable.Add("FlipStrokeAlign", template.flipStrokeAlign);

        propertyTable.Add("RotationRangeMinX", template.rotationRangeMin.x);
        propertyTable.Add("RotationRangeMinY", template.rotationRangeMin.y);
        propertyTable.Add("RotationRangeMinZ", template.rotationRangeMin.z);

        propertyTable.Add("RotationRangeMaxX", template.rotationRangeMax.x);
        propertyTable.Add("RotationRangeMaxY", template.rotationRangeMax.y);
        propertyTable.Add("RotationRangeMaxZ", template.rotationRangeMax.z);
        #endregion

        #region Position Settings Vars
        propertyTable.Add("PositionOffsetX", template.positionOffset.x);
        propertyTable.Add("PositionOffsetY", template.positionOffset.y);
        propertyTable.Add("PositionOffsetZ", template.positionOffset.z);
        #endregion

        #region Scale Settings Vars
        propertyTable.Add("ScaleAbsolute", template.scaleAbsolute);

        //The minimum and maximum possible scale
        propertyTable.Add("ScaleMin", template.scaleMin);
        propertyTable.Add("ScaleMax", template.scaleMax);

        //The minimum and maximum current scale range setting
        propertyTable.Add("ScaleRandMinX", template.scaleRandMin.x);
        propertyTable.Add("ScaleRandMinY", template.scaleRandMin.y);
        propertyTable.Add("ScaleRandMinZ", template.scaleRandMin.z);

        propertyTable.Add("ScaleRandMaxX", template.scaleRandMax.x);
        propertyTable.Add("ScaleRandMaxY", template.scaleRandMax.y);
        propertyTable.Add("ScaleRandMaxZ", template.scaleRandMax.z);

        propertyTable.Add("ScaleRandMinUniform", template.scaleRandMinUniform);

        propertyTable.Add("ScaleRandMaxUniform", template.scaleRandMaxUniform);

        propertyTable.Add("ScaleUniform", template.scaleUniform);
        #endregion

        #region Sorting Vars
        //Selection
        propertyTable.Add("PaintToSelection", template.paintToSelection);

        //Layers
        propertyTable.Add("PaintToLayer", template.paintToLayer);

        propertyTable.Add("LayerIndex", template.layerIndex);

        propertyTable.Add("GroupObjects", template.groupObjects);

        //propertyTable.Add("GroupIndex",template.groupIndex);
        propertyTable.Add("GroupName", template.groupName);
        #endregion

        #region Eraser Vars
        propertyTable.Add("EraseByGroup", template.eraseByGroup);
        propertyTable.Add("EraseBySelected", template.eraseBySelected);
        #endregion

        //New Prefab Save
        string prefabGroupString = string.Empty;

        for (int i = 0; i < template.prefabGroup.Length; i++)
        {
            prefabGroupString += "/" + AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(template.prefabGroup[i].prefab)) + "-" + template.prefabGroup[i].weight.ToString();
        }

        propertyTable.Add("PrefabGUIDList", prefabGroupString);

        return(propertyTable);
    }
示例#5
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);
    }
示例#6
0
	//Load settings into the window - from the file associated with the provided tab index
	private void SwitchToTab(int tabIndex)
	{//Debug.Log(tabIndex);
		if(tabIndex == -1)
			liveTemplate = new qb_Template();
			
		else
		{	
			if(brushTemplates[tabIndex] == null)
				return;
		
			liveTemplate = brushTemplates[tabIndex];
			
		}
		
		clearSelection = true;
		liveTemplateIndex = tabIndex;
		prefabPaneOpen = false;
		UpdateLayers();
		UpdateCompoundLayerMask();
		UpdateCompoundPaintToSelection();
	//	RefreshPrefabIcons();
	}
示例#7
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);
    }
示例#8
0
	private void ClearLiveTemplate()
	{			
		clearSelection = true;
		liveTemplate = new qb_Template();//ScriptableObject.CreateInstance<qb_Template>();		
	}
示例#9
0
	private void RestoreTemplateDefaults()
	{
		if(liveTemplateIndex < 0)
			return;
		
		string	slotName = string.Empty;
		
		if(liveTemplate != null)
		{
			slotName = liveTemplate.brushName;
		}
		
		clearSelection = true;
		brushTemplates[liveTemplateIndex] = new qb_Template();
		brushTemplates[liveTemplateIndex].brushName = slotName;
		brushTemplates[liveTemplateIndex].lastKnownAs = slotName;
		
		SwitchToTab(liveTemplateIndex);
		liveTemplate.dirty = true;
		liveTemplate.live = true;
	}
示例#10
0
	//Save an open template to a file - this is the final commit of a save 
	private void SaveSettings(qb_Template template)
	{
		if(template.brushName == string.Empty)
			return; //this should be a popup and already is - code should be unreachable, but left here as a safeguard
		
		template.lastKnownAs = template.brushName;
		template.dirty = false;
		qb_Utility.SaveToDisk(template, directory);
		UpdateTemplateSignatures();
		AssetDatabase.Refresh();
		window.Repaint();
	}
示例#11
0
	//Attempt to save a template to file. This is the wrapper for SaveSettings() 
	//It runs through the different permutations of a save situation and pops dialogs if needed
	private bool TrySaveTemplate(qb_Template template)
	{
		bool fileOnDisk = TemplateExistsOnDisk(template.brushName);
		//int alreadyLoadedIndex = TemplateAlreadyOpen(template.brushName);
		//File with this name exists on disk and the template we are attempting to save was not known by this name last time it was saved or loaded

		if(fileOnDisk == true && template.lastKnownAs != template.brushName)
		{
			if(EditorUtility.DisplayDialog("File Override", "A template file with this name exists on disk, override the file?", "Override", "Cancel")) 
			{
				SaveSettings(template);
				return true;
			}
			
		}
		//Otherwise just save
		else
		{
			if(template.brushName == string.Empty)
			{
				EditorUtility.DisplayDialog("File Name Not Set","A template file must be named before it can be saved","Ok");
			
				//this needs to be replaced with a name entry dialog
				
				//Name Entry Field
				//Save (disabled unless a name exists,Cancel
				//this should basically call this same function again and return its bool when done so if cancel that one will return false or could rely on flow to return false
				//this should account for overrides etc we could pop back to the naming dialog if it returns false
			}
		
			else
			{
				SaveSettings(template);
				return true;
			}
		}
		
		//additional permutation
		//file with that name is already open in the tool
		
		return false;
	}
示例#12
0
	private static qb_RaycastResult DoPlacementRaycast(Vector3 castPosition,Vector3 rayDirection, qb_Template curTemplate)
	{
		RaycastHit hit = new RaycastHit();
		bool success = false;
		
	//	Physics.Raycast(castPosition + (-0.1f * rayDirection),rayDirection,out hit,float.MaxValue,//curTemplate.layerIndex);//obsolete-prob	
		//if the current template is 
		
		if(curTemplate.paintToLayer == false)
			Physics.Raycast(castPosition + (-0.1f * rayDirection),rayDirection,out hit,curTemplate.brushRadius);//float.MaxValue);
		
		else if(curTemplate.paintToLayer == true && curTemplate.layerIndex != -1)
			Physics.Raycast(castPosition + (-0.1f * rayDirection),rayDirection,out hit,curTemplate.brushRadius, curTemplate.layerIndex);
		
		if(hit.collider != null)
		{
			success = true;
			
			if(curTemplate.paintToLayer == true)
			{
				//if(hit.collider.gameObject.layer != window.layerIndex)
				if( (1 << hit.collider.gameObject.layer & curTemplate.layerIndex) == 0)
					success = false;
			}
			
			if(curTemplate.paintToSelection == true)
			{
				
				Transform[] selectedObjects = Selection.transforms;
				bool contains = ArrayUtility.Contains(selectedObjects,hit.collider.transform);
				
				if(!contains)
					success = false;
			}
		}
		
		qb_RaycastResult result = new qb_RaycastResult(success,hit);
		
		return result;
	}
示例#13
0
	static Object PickRandPrefab(qb_Template  curTemplate)
	{
		
		float totalWeight = 0f;
		for(int i = 0; i < curTemplate.prefabGroup.Length ; i++)
		{
			totalWeight += curTemplate.prefabGroup[i].weight;
		}
		
		float randomNumber = Random.Range(0f,totalWeight);
		
		float weightSum = 0f;
		int chosenIndex = 0;
		
		for(int x = 0; x < curTemplate.prefabGroup.Length; x++)
		{
			weightSum += curTemplate.prefabGroup[x].weight;

			if(randomNumber < weightSum)
			{
				chosenIndex = x;
				break;
			}
		}
		
		return curTemplate.prefabGroup[chosenIndex].prefab;
	}			
示例#14
0
	private void TemplateMenuItemCallback(object obj)
	{ 
		KeyValuePair<int,int> pair = (KeyValuePair<int,int>)obj;
		
		int fileIndex = pair.Key;	//The file's index in the dropDown
		int tabIndex = pair.Value;	//index of the slot we want to load into
		int count = brushTemplates.Length;
			
		//If the user selected "New Template"
		if(fileIndex == -1)
		{
			//if this is the end tab
			if(tabIndex == count)
			{	ArrayUtility.Add(ref brushTemplates,null);
			
				qb_Template newTemplate = new qb_Template();
				brushTemplates[tabIndex] = newTemplate;
				newTemplate.live = true;
			}
			
			else
			{
				if(brushTemplates[tabIndex].dirty == true)
				{
					int option = EditorUtility.DisplayDialogComplex("Template Has Changed", "The Template '" + brushTemplates[tabIndex].brushName + "' in the tab which you are trying to use has changed since it was last saved.", "Save and Close","Close W/O Saving","Cancel");
					
					switch(option)
					{
						case 0:
							if(TrySaveTemplate(brushTemplates[tabIndex]))
								goto case 1;						
						break;
					
						case 1:
						   qb_Template newTemplate = new qb_Template();
						   brushTemplates[tabIndex] = newTemplate;
						   newTemplate.live = true;				
						break;
						
						case 2:
						break;
					}
				}
			}
		}
		
		//If the user did select a template from the list
		else
		{
			//here, we need to check if the requested template is already in one of the tabs
			string fileName = templateSignatures[fileIndex].name;
			
			//The slot into which the file is already loaded (if it is)
			int alreadyLoadedIndex = TemplateAlreadyOpen(fileName);
			
			//if the selected template is not already loaded
			if(alreadyLoadedIndex == -1)
			{			
				if(tabIndex == count)
				{	ArrayUtility.Add(ref brushTemplates,null);

					brushTemplates[tabIndex] = qb_Utility.LoadFromDisk(templateSignatures[fileIndex].directory);
					QBLog("Loaded template '" + fileName + "' into slot " + (tabIndex + 1).ToString("00"));
				}
				
				else
				{
					if(brushTemplates[tabIndex].dirty == true)
					{
						int option = EditorUtility.DisplayDialogComplex("Template Has Changed", "The Template '" + brushTemplates[tabIndex].brushName + "' in the tab which you are trying to use has changed since it was last saved.", "Save and Close","Close W/O Saving","Cancel");
						
						switch(option)
						{
							case 0:
								if(TrySaveTemplate(brushTemplates[tabIndex]))
									goto case 1;						
							break;
							
							case 1:
								brushTemplates[tabIndex] = qb_Utility.LoadFromDisk(templateSignatures[fileIndex].directory);
								QBLog("Loaded template '" + fileName + "' into slot " + (tabIndex + 1).ToString("00"));				
							break;
							
							case 2:
							break;
						}
					}
					
					else
					{
						brushTemplates[tabIndex] = qb_Utility.LoadFromDisk(templateSignatures[fileIndex].directory);
						QBLog("Loaded template '" + fileName + "' into slot " + (tabIndex + 1).ToString("00"));	
					}
				}
			}
			
			//if the selected template is already loaded
			else
			{
				//If the tab index we are wanting is not the same as the index of the matching already loaded temaplate
				if(tabIndex != alreadyLoadedIndex)
				{
					if(EditorUtility.DisplayDialog("Template Already Open", "This template '" + fileName + "' is already open in tab " + (alreadyLoadedIndex+1).ToString("00") + ". Would you like to move '" + fileName + "' to this tab?","Move","Cancel"))
					{
						//if this is the end tab - append a tab to the end, and close the tab where the template was alread loaded
						if(tabIndex == count)
						{
							ArrayUtility.Add(ref brushTemplates,null);
							brushTemplates[tabIndex] = brushTemplates[alreadyLoadedIndex];
							
							CloseTab(alreadyLoadedIndex);
							tabIndex -= 1;
						}
						
						else
						{
							qb_Template templateToSwap			=	brushTemplates[tabIndex]; //This may be null - it doesn't matter - basically the template to move out of the way
							brushTemplates[tabIndex]			=	brushTemplates[alreadyLoadedIndex];
							brushTemplates[alreadyLoadedIndex]	=	templateToSwap;
							
							if(templateToSwap == null)
								CloseTab(alreadyLoadedIndex);
							
							string fName = fileName;
							if(fName == string.Empty)
								fName = "Unnamed"; 
							
							QBLog("Moved template '" + fName + "' from slot " + (alreadyLoadedIndex + 1).ToString("00") +" to slot " + (tabIndex + 1).ToString("00"));
						}
					}
					
					//if user canceled
					else
					{
						//this whole else statement is here just to prevent from trying to switch to an index that's out of rage
						if(tabIndex == count)
							tabIndex -= 1;
					}
				}
				
				else
				{
					if(EditorUtility.DisplayDialog("Reload Template '" + fileName + "'?", "The template you are trying to load '" + fileName + "' is already open in this tab. Would you like to reload '" + fileName + "' from disk and lose any changes since last saving?","Reload","Cancel"))
					{
						brushTemplates[tabIndex] = qb_Utility.LoadFromDisk(templateSignatures[fileIndex].directory);
						QBLog("Loaded template '" + fileName + "' into slot " + (tabIndex + 1).ToString("00"));
					}
				}
				//else 
				//do nothing - or maybe prompt user to see if he wants a reload from disk				
			}
			//if it is not then do go ahead with the load
			
			//if it is, either move the template to this slot, or if it is already in this slot then do nothing 
			//- or prompt user to ask if he wants a to re-load from disk or keep current version. 
		}
		UpdateAreActive();
		SwitchToTab(tabIndex);
	}