예제 #1
0
	public static bool Deserialize(string txt, out Decal decal)
	{
		decal = new Decal();

		string[] split = txt.Replace("{", "").Replace("}", "").Trim().Split('\n');
		if(split.Length < 11) return false;
		
		decal.name 		= split[0];
		decal.id 		= split[1];

		#if UNITY_EDITOR
		decal.texture = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(decal.id), typeof(Texture2D));
		#endif
		
		decal.rotation = DefaultRotation;
		if(!Vec3WithString(split[2], ref decal.rotation))
			Debug.LogWarning("Failed parsing default rotation values.  Using defaults.");
		
		decal.scale = DefaultScale;
		if(!Vec3WithString(split[3], ref decal.scale))
			Debug.LogWarning("Failed parsing default scale values.  Using defaults.");
		
		Vector4 v4 = Vector4.one;	// my laziness knows no bounds
		if(!Vec4WithString(split[4], ref v4))
			Debug.LogWarning("Failed parsing atlas rect.  Using default.");
		decal.atlasRect = Vec4ToRect(v4);

		decal.orgGroup = 0;
		if(!int.TryParse(split[5], out decal.orgGroup))
			Debug.LogWarning("Failed parsing organizational group.  Setting to group 0");

		decal.atlasGroup = 0;
		if(!int.TryParse(split[6], out decal.atlasGroup))
			Debug.LogWarning("Failed parsing atlas group.  Setting to group 0");

		decal.orgIndex = 0;
		if(!int.TryParse(split[7], out decal.orgIndex))
			Debug.LogWarning("Failed parsing organizational group.  Setting to group 0");

		decal.atlasIndex = 0;
		if(!int.TryParse(split[8], out decal.atlasIndex))
			Debug.LogWarning("Failed parsing atlas group.  Setting to group 0");

		int i;

		decal.rotationPlacement = Placement.Fixed;
		if(!int.TryParse(split[9], out i))
			Debug.LogWarning("Failed parsing rotationPlacement.  Setting to \"Fixed\"");
		else
			decal.rotationPlacement = (Placement)i;

		decal.scalePlacement = Placement.Fixed;
		if(!int.TryParse(split[10], out i))
			Debug.LogWarning("Failed parsing scalePlacement.  Setting to \"Fixed\"");
		else
			decal.scalePlacement = (Placement)i;

		return true;
	}
예제 #2
0
 /**
  * Returns the Shader associated with this decal.  If no shader set, return the default.
  */
 public Shader ShaderWithDecal(QD.Decal decal)
 {
     if (shaders != null && decal.atlasIndex < shaders.Length)
     {
         return(Shader.Find(shaders[decal.atlasIndex]));
     }
     else
     {
         return(DefaultShader);
     }
 }
예제 #3
0
 /**
  * Get the Material associated with this decal.  Can be null if sheet isn't packed yet.
  */
 public bool MaterialWithDecal(QD.Decal decal, out Material mat)
 {
     if (decal.isPacked && materials != null && decal.atlasIndex < materials.Length)
     {
         mat = (Material)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(materials[decal.atlasIndex]), typeof(Material));
     }
     else
     {
         mat = null;
     }
     return(mat != null);
 }
예제 #4
0
파일: Decal.cs 프로젝트: Terijan/melodiesel
        public static bool Deserialize(string txt, out Decal decal)
        {
            decal = new Decal();

            string[] split = txt.Replace("{", "").Replace("}", "").Trim().Split('\n');
            if (split.Length < 11)
            {
                return(false);
            }

            decal.name = split[0];
            decal.id   = split[1];

                #if UNITY_EDITOR
            decal.texture = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(decal.id), typeof(Texture2D));
                #endif

            decal.rotation = DefaultRotation;
            if (!Vec3WithString(split[2], ref decal.rotation))
            {
                Debug.LogWarning("Failed parsing default rotation values.  Using defaults.");
            }

            decal.scale = DefaultScale;
            if (!Vec3WithString(split[3], ref decal.scale))
            {
                Debug.LogWarning("Failed parsing default scale values.  Using defaults.");
            }

            Vector4 v4 = Vector4.one;           // my laziness knows no bounds
            if (!Vec4WithString(split[4], ref v4))
            {
                Debug.LogWarning("Failed parsing atlas rect.  Using default.");
            }
            decal.atlasRect = Vec4ToRect(v4);

            decal.orgGroup = 0;
            if (!int.TryParse(split[5], out decal.orgGroup))
            {
                Debug.LogWarning("Failed parsing organizational group.  Setting to group 0");
            }

            decal.atlasGroup = 0;
            if (!int.TryParse(split[6], out decal.atlasGroup))
            {
                Debug.LogWarning("Failed parsing atlas group.  Setting to group 0");
            }

            decal.orgIndex = 0;
            if (!int.TryParse(split[7], out decal.orgIndex))
            {
                Debug.LogWarning("Failed parsing organizational group.  Setting to group 0");
            }

            decal.atlasIndex = 0;
            if (!int.TryParse(split[8], out decal.atlasIndex))
            {
                Debug.LogWarning("Failed parsing atlas group.  Setting to group 0");
            }

            int i;

            decal.rotationPlacement = Placement.Fixed;
            if (!int.TryParse(split[9], out i))
            {
                Debug.LogWarning("Failed parsing rotationPlacement.  Setting to \"Fixed\"");
            }
            else
            {
                decal.rotationPlacement = (Placement)i;
            }

            decal.scalePlacement = Placement.Fixed;
            if (!int.TryParse(split[10], out i))
            {
                Debug.LogWarning("Failed parsing scalePlacement.  Setting to \"Fixed\"");
            }
            else
            {
                decal.scalePlacement = (Placement)i;
            }

            return(true);
        }
예제 #5
0
    void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

                #if UNITY_STANDALONE_OSX
        EventModifiers em = e.modifiers;                // `&=` consumes the event.
        if ((em &= EventModifiers.Shift) != EventModifiers.Shift)
        {
            return;
        }

        int controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
        HandleUtility.AddDefaultControl(controlID);
                #endif

                #if UNITY_STANDALONE_OSX
        if (e.type == EventType.MouseUp && ((e.button == RIGHT_MOUSE_BUTTON && e.modifiers == EventModifiers.Shift) || (e.modifiers == (EventModifiers.Shift | EventModifiers.Control))))
                #else
        if (e.type == EventType.MouseUp && e.button == RIGHT_MOUSE_BUTTON && e.modifiers == EventModifiers.Shift)
                #endif
        {
            if (selected.Count < 1 || decalView == DecalView.Atlas)
            {
                return;
            }

            int key = selected.Keys.ToList()[(int)Random.Range(0, selected.Count)];
            if (selected[key].Count < 1)
            {
                return;
            }
            int val = (int)Random.Range(0, selected[key].Count);

            int grpIndex = key;
            int texIndex = selected[key][val];

            QD.Decal decal = decalGroups[grpIndex].decals[texIndex];

            Texture2D tex = decal.texture;

            Material mat;

            /**
             * Atlas hasn't been packed yet, but we still want decals to share a single material.
             */
            if (!database.MaterialWithDecal(decal, out mat))
            {
                // Make sure that atlasRect is 0,0,1,1 and packed == false;
                decal.isPacked  = false;
                decal.atlasRect = new Rect(0, 0, 1, 1);

                GameObject[] existingDecals = qdUtil.FindDecalsWithTexture(tex);

                if (existingDecals == null || existingDecals.Length < 1)
                {
                    mat             = new Material(database.ShaderWithDecal(decal));
                    mat.mainTexture = tex;
                }
                else
                {
                    mat = existingDecals[0].GetComponent <MeshRenderer>().sharedMaterial;
                }
            }

            Rect r = decal.isPacked ? decal.atlasRect : new Rect(0f, 0f, 1f, 1f);

            GameObject decalGo;
            Transform  hit;

            if (PlaceDecal(e.mousePosition, mat, r,
                           decal.rotationPlacement == Placement.Random ? Random.Range(decal.rotation.x, decal.rotation.y) : decal.rotation.z,
                           decal.scalePlacement == Placement.Random ? Random.Range(decal.scale.x, decal.scale.y) : decal.scale.z,
                           out decalGo,
                           out hit))
            {
                if (qd_Preferences.GetBool(qd_Constant.ParentToHitTransform))
                {
                    decalGo.transform.parent = hit;

                    if (decalGo.transform.localScale != Vector3.one)
                    {
                        decalGo.GetComponent <qd_Decal>().FreezeTransform();
                    }
                }
                else
                {
                    decalGo.transform.parent = DecalParent.transform;
                }

                Selection.objects = new Object[1] {
                    decalGo
                };
                SceneView.RepaintAll();

                // DO NOT USE THE EVENT
                // unitay needs shift clicks to register in order
                // to release the view mode shortcut
            }
        }
    }