void OnEnable()
		{
			m_SpriteMeshInstance = target as SpriteMeshInstance;
			m_SortingOrder = serializedObject.FindProperty("m_SortingOrder");
			m_SortingLayerID = serializedObject.FindProperty("m_SortingLayerID");
			m_SpriteMeshProperty = serializedObject.FindProperty("m_SpriteMesh");
			m_ColorProperty = serializedObject.FindProperty("m_Color");
			m_MaterialsProperty = serializedObject.FindProperty("m_Materials.Array");
			m_BonesProperty = serializedObject.FindProperty("m_Bones.Array");
			m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms.Array");

			UpgradeToMaterials();
			UpgradeToBoneTransforms();

			if(m_SpriteMeshInstance.cachedRenderer)
			{
				foreach(Material material in m_SpriteMeshInstance.cachedRenderer.sharedMaterials)
				{
					if(material)
					{
						material.hideFlags = HideFlags.HideInInspector;
					}
				}
			}

			UpdateSpriteMeshData();
			SetupBoneList();

			EditorUtility.SetSelectedWireframeHidden(m_SpriteMeshInstance.cachedRenderer, !m_SpriteMeshInstance.cachedSkinnedRenderer);
		}
Esempio n. 2
0
    public void Sort_renderer(GameObject object_to_sort, HexagonCell _target_location)
    {
        Anima2D.SpriteMeshInstance Sprite_Mesh = object_to_sort.GetComponent <Anima2D.SpriteMeshInstance>();
        if (Sprite_Mesh != null)
        {
            Sprite_Mesh.sortingOrder = Sprite_Mesh.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }

        SpriteRenderer sprite_rend = object_to_sort.GetComponent <SpriteRenderer>();

        if (sprite_rend != null)
        {
            sprite_rend.sortingOrder = sprite_rend.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }

        Canvas canvas_rend = object_to_sort.GetComponent <Canvas>();

        if (canvas_rend != null)
        {
            canvas_rend.sortingOrder = canvas_rend.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }
    }
        public static SpriteMeshInstance CreateSpriteMeshInstance(SpriteMesh spriteMesh, GameObject gameObject, bool undo = true)
        {
            SpriteMeshInstance spriteMeshInstance = null;

            if (spriteMesh && gameObject)
            {
                if (undo)
                {
                    spriteMeshInstance = Undo.AddComponent <SpriteMeshInstance>(gameObject);
                }
                else
                {
                    spriteMeshInstance = gameObject.AddComponent <SpriteMeshInstance>();
                }
                spriteMeshInstance.spriteMesh     = spriteMesh;
                spriteMeshInstance.sharedMaterial = defaultMaterial;

                SpriteMeshData spriteMeshData = SpriteMeshUtils.LoadSpriteMeshData(spriteMesh);

                List <Bone2D> bones = new List <Bone2D>();
                List <string> paths = new List <string>();

                Vector4 zero = new Vector4(0f, 0f, 0f, 1f);

                foreach (BindInfo bindInfo in spriteMeshData.bindPoses)
                {
                    Matrix4x4 m = spriteMeshInstance.transform.localToWorldMatrix * bindInfo.bindPose.inverse;

                    GameObject bone = new GameObject(bindInfo.name);

                    if (undo)
                    {
                        Undo.RegisterCreatedObjectUndo(bone, Undo.GetCurrentGroupName());
                    }

                    Bone2D boneComponent = bone.AddComponent <Bone2D>();

                    boneComponent.localLength = bindInfo.boneLength;
                    bone.transform.position   = m * zero;
                    bone.transform.rotation   = m.GetRotation();
                    bone.transform.parent     = gameObject.transform;

                    bones.Add(boneComponent);
                    paths.Add(bindInfo.path);
                }

                BoneUtils.ReconstructHierarchy(bones, paths);

                spriteMeshInstance.bones = bones;

                SpriteMeshUtils.UpdateRenderer(spriteMeshInstance, undo);

                EditorUtility.SetDirty(spriteMeshInstance);
            }

            return(spriteMeshInstance);
        }
        static int FindBindInfo(BindInfo bindInfo, SpriteMeshInstance spriteMeshInstance)
        {
            if (spriteMeshInstance)
            {
                return(FindBindInfo(bindInfo, SpriteMeshUtils.LoadSpriteMeshData(spriteMeshInstance.spriteMesh)));
            }

            return(-1);
        }
Esempio n. 5
0
		static void Cleanup()
		{
			init = false;
			spriteMesh = null;
			instance = null;
			currentDestination = null;
			parentTransform = null;
			s_InstanceBones.Clear();
		}
Esempio n. 6
0
    /// <summary>
    /// Coroutine done when the Ringleader teleports. Fades the Ringleader's sprites into visibility.
    /// </summary>
    /// <param name="sm">A sprite instance</param>
    /// <param name="duration">Duration for the fading.</param>
    /// <returns></returns>
    IEnumerator FadeIn(Anima2D.SpriteMeshInstance sm, float duration)
    {
        ringleaderAnimatable.TeleportIn();

        while (ringleaderAnimatable.IsPlaying())
        {
            yield return(null);
        }
    }
Esempio n. 7
0
 static void Cleanup()
 {
     init               = false;
     spriteMesh         = null;
     instance           = null;
     currentDestination = null;
     parentTransform    = null;
     s_InstanceBones.Clear();
 }
Esempio n. 8
0
    public IEnumerator fade_out(Anima2D.SpriteMeshInstance sm_instance)
    {
        Color color = sm_instance.color;

        while (color.a > 0)
        {
            color.a          -= 0.1f * Time.deltaTime;
            sm_instance.color = color;
            yield return(null);
        }
    }
Esempio n. 9
0
    //Anima2D.SpriteMesh instanceItem;
    // Player/PlayerAni/Mesh/Player_HandGun

    // Use this for initialization
    void Start()
    {
        item1 = GetComponent <Anima2D.SpriteMeshInstance>();
        adf   = GetComponent <Anima2D.SpriteMeshAnimation>().frames;

        //item1.spriteMesh = Resources.Load<Anima2D.SpriteMesh>("SpriteMesh/PlayerItem/buki sozai1_1") as Anima2D.SpriteMesh;
        //adf[0] = Resources.Load<Anima2D.SpriteMesh>("SpriteMesh/PlayerItem/buki sozai1_1") as Anima2D.SpriteMesh;

        //instanceItem = GetComponent<Anima2D.SpriteMeshInstance>().spriteMesh;
        //for(int i = 0; i < adf.Length; i++){ Debug.Log(adf[i]); }
        //Debug.Log(instanceItem);
        //instanceItem = Resources.Load<Anima2D.SpriteMesh>("buki sozai1_1") as Anima2D.SpriteMesh; <--画像変わらない
    }
Esempio n. 10
0
        public void Clear()
        {
            spriteMesh         = null;
            spriteMeshInstance = null;
            selectedBone       = null;
            selectedEdge       = null;
            selectedVertices.Clear();
            texVertices.Clear();
            indexedEdges.Clear();
            indices.Clear();

            isDirty = false;
        }
        static void ContextCreateSpriteMesh(MenuCommand menuCommand)
        {
            GameObject     spriteRendererGO = Selection.activeGameObject;
            SpriteRenderer spriteRenderer   = null;
            SpriteMesh     spriteMesh       = null;

            int sortingLayerID = 0;
            int sortingOrder   = 0;

            if (spriteRendererGO)
            {
                spriteRenderer = spriteRendererGO.GetComponent <SpriteRenderer>();
            }

            if (spriteRenderer &&
                spriteRenderer.sprite)
            {
                sortingLayerID = spriteRenderer.sortingLayerID;
                sortingOrder   = spriteRenderer.sortingOrder;

                SpriteMesh overrideSpriteMesh = SpriteMeshPostprocessor.GetSpriteMeshFromSprite(spriteRenderer.sprite);

                if (overrideSpriteMesh)
                {
                    spriteMesh = overrideSpriteMesh;
                }
                else
                {
                    spriteMesh = SpriteMeshUtils.CreateSpriteMesh(spriteRenderer.sprite);
                }
            }

            if (spriteMesh)
            {
                Undo.SetCurrentGroupName("create SpriteMeshInstance");
                Undo.DestroyObjectImmediate(spriteRenderer);
                SpriteMeshInstance spriteMeshInstance =
                    SpriteMeshUtils.CreateSpriteMeshInstance(spriteMesh, spriteRendererGO, true);

                spriteMeshInstance.sortingLayerID = sortingLayerID;
                spriteMeshInstance.sortingOrder   = sortingOrder;

                Selection.activeGameObject = spriteRendererGO;
            }
            else
            {
                Debug.Log("Select a SpriteRenderer with a Sprite to convert to SpriteMesh");
            }
        }
Esempio n. 12
0
        public static GameObject InstantiateForAnimatorPreview(UnityEngine.Object original)
        {
            /*
             * GameObject result = null;
             * MethodInfo methodInfo = typeof(EditorUtility).GetMethod("InstantiateForAnimatorPreview", BindingFlags.Static | BindingFlags.NonPublic);
             * if(methodInfo != null)
             * {
             *      object[] parameters = new object[] { original };
             *      result = (GameObject) methodInfo.Invoke(null,parameters);
             * }
             */

            GameObject result = GameObject.Instantiate(original) as GameObject;

            List <Behaviour> behaviours = new List <Behaviour>();

            result.GetComponentsInChildren <Behaviour>(false, behaviours);

            foreach (Behaviour behaviour in behaviours)
            {
                SpriteMeshInstance spriteMeshInstance = behaviour as SpriteMeshInstance;

                if (spriteMeshInstance && spriteMeshInstance.spriteMesh && spriteMeshInstance.spriteMesh.sprite)
                {
                    Material material = spriteMeshInstance.sharedMaterial;

                    if (material)
                    {
                        Material materialClone = GameObject.Instantiate(material);
                        materialClone.hideFlags   = HideFlags.HideAndDontSave;
                        materialClone.mainTexture = spriteMeshInstance.spriteMesh.sprite.texture;

                        spriteMeshInstance.cachedRenderer.sharedMaterial = materialClone;
                    }
                }

                if (!(behaviour is Ik2D)
#if UNITY_5_6_OR_NEWER
                    && !(behaviour is SortingGroup)
#endif
                    )
                {
                    behaviour.enabled = false;
                }
            }

            return(result);
        }
Esempio n. 13
0
        static void CreateInstance()
        {
            instance = SpriteMeshUtils.CreateSpriteMeshInstance(spriteMesh, false);

            if (instance)
            {
                s_InstanceBones = instance.bones;

                instance.transform.parent = parentTransform;

                if (parentTransform)
                {
                    instance.transform.localPosition = Vector3.zero;
                }
            }
        }
Esempio n. 14
0
		static void CreateInstance()
		{
			instance = SpriteMeshUtils.CreateSpriteMeshInstance(spriteMesh,false);

			if(instance)
			{
				s_InstanceBones = instance.bones;

				instance.transform.parent = parentTransform;
				
				if(parentTransform)
				{
					instance.transform.localPosition = Vector3.zero;
				}
			}
		}
Esempio n. 15
0
        public static GameObject InstantiateForAnimatorPreview(UnityEngine.Object original)
        {
            GameObject result = GameObject.Instantiate(original) as GameObject;

            List <Behaviour> behaviours = new List <Behaviour>();

            result.GetComponentsInChildren <Behaviour>(false, behaviours);

            foreach (Behaviour behaviour in behaviours)
            {
                SpriteMeshInstance spriteMeshInstance = behaviour as SpriteMeshInstance;

                if (spriteMeshInstance && spriteMeshInstance.spriteMesh && spriteMeshInstance.spriteMesh.sprite)
                {
                    Material material = spriteMeshInstance.sharedMaterial;

                    if (material)
                    {
                        Material materialClone = GameObject.Instantiate(material);
                        materialClone.hideFlags   = HideFlags.HideAndDontSave;
                        materialClone.mainTexture = spriteMeshInstance.spriteMesh.sprite.texture;

                        spriteMeshInstance.sharedMaterial = materialClone;
                        spriteMeshInstance.cachedRenderer.sharedMaterial = materialClone;
                    }
                }

                if (behaviour == null ||
                    behaviour is Ik2D ||
                    behaviour is SpriteMeshAnimation
#if UNITY_5_6_OR_NEWER
                    || behaviour is SortingGroup
#endif
                    )
                {
                    continue;
                }
                else
                {
                    behaviour.enabled = false;
                }
            }

            return(result);
        }
Esempio n. 16
0
        static void ContextCreateSpriteMesh(MenuCommand menuCommand)
        {
            GameObject     spriteRendererGO = Selection.activeGameObject;
            SpriteRenderer spriteRenderer   = null;
            SpriteMesh     spriteMesh       = null;

            if (spriteRendererGO)
            {
                spriteRenderer = spriteRendererGO.GetComponent <SpriteRenderer>();
            }

            if (spriteRenderer)
            {
                spriteMesh = SpriteMeshUtils.CreateSpriteMesh(spriteRenderer.sprite);
            }

            if (spriteMesh)
            {
                Undo.DestroyObjectImmediate(spriteRenderer);

                string spriteMeshPath = AssetDatabase.GetAssetPath(spriteMesh);

                Mesh     mesh     = AssetDatabase.LoadAssetAtPath(spriteMeshPath, typeof(Mesh)) as Mesh;
                Material material = AssetDatabase.LoadAssetAtPath(spriteMeshPath, typeof(Material)) as Material;

                SpriteMeshInstance spriteMeshRenderer = spriteRendererGO.AddComponent <SpriteMeshInstance>();
                spriteMeshRenderer.spriteMesh = spriteMesh;

                MeshFilter meshFilter = spriteRendererGO.AddComponent <MeshFilter>();
                meshFilter.sharedMesh = mesh;

                MeshRenderer renderer = spriteRendererGO.AddComponent <MeshRenderer>();
                renderer.sharedMaterial = material;

                Undo.RegisterCreatedObjectUndo(meshFilter, "Create SpriteMesh");
                Undo.RegisterCreatedObjectUndo(renderer, "Create SpriteMesh");

                Selection.activeGameObject = spriteRendererGO;
            }
            else
            {
                Debug.Log("Select a SpriteRenderer with a Sprite to convert to SpriteMesh");
            }
        }
Esempio n. 17
0
        void OnEnable()
        {
            m_SpriteMeshInstance     = target as SpriteMeshInstance;
            m_SortingOrder           = serializedObject.FindProperty("m_SortingOrder");
            m_SortingLayerID         = serializedObject.FindProperty("m_SortingLayerID");
            m_SpriteMeshProperty     = serializedObject.FindProperty("m_SpriteMesh");
            m_ColorProperty          = serializedObject.FindProperty("m_Color");
            m_MaterialsProperty      = serializedObject.FindProperty("m_Materials.Array");
            m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms.Array");

            UpgradeToMaterials();

            UpdateSpriteMeshData();
            SetupBoneList();

#if UNITY_5_5_OR_NEWER
#else
            EditorUtility.SetSelectedWireframeHidden(m_SpriteMeshInstance.cachedRenderer, !m_SpriteMeshInstance.cachedSkinnedRenderer);
#endif
        }
Esempio n. 18
0
        static bool Bindeable(SpriteMeshInstance targetSpriteMeshInstance,
                              SpriteMeshInstance destinationSpriteMeshInstance)
        {
            bool bindeable = false;

            if (targetSpriteMeshInstance &&
                destinationSpriteMeshInstance &&
                targetSpriteMeshInstance.spriteMesh &&
                destinationSpriteMeshInstance.spriteMesh &&
                targetSpriteMeshInstance.spriteMesh != destinationSpriteMeshInstance.spriteMesh &&
                destinationSpriteMeshInstance.cachedSkinnedRenderer)
            {
                SpriteMeshData targetData      = SpriteMeshUtils.LoadSpriteMeshData(targetSpriteMeshInstance.spriteMesh);
                SpriteMeshData destinationData =
                    SpriteMeshUtils.LoadSpriteMeshData(destinationSpriteMeshInstance.spriteMesh);

                bindeable = true;

                if (destinationData.bindPoses.Length >= targetData.bindPoses.Length)
                {
                    for (int i = 0; i < targetData.bindPoses.Length; ++i)
                    {
                        if (bindeable)
                        {
                            BindInfo bindInfo = targetData.bindPoses[i];

                            if (FindBindInfo(bindInfo, destinationData) < 0)
                            {
                                bindeable = false;
                            }
                        }
                    }
                }
                else
                {
                    bindeable = false;
                }
            }

            return(bindeable);
        }
Esempio n. 19
0
 // Use this for initialization
 void Start()
 {
     handgunMesh    = handgun.GetComponent <Anima2D.SpriteMeshInstance>();
     handgunAniMesh = handgun.GetComponent <Anima2D.SpriteMeshAnimation>().frames;
     rifleMesh      = rifle.GetComponent <Anima2D.SpriteMeshInstance>();
     rifleAniMesh   = rifle.GetComponent <Anima2D.SpriteMeshAnimation>().frames;
     syousaiPanel   = transform.root.Find("syousaiPanel");
     image          = syousaiPanel.transform.Find("Image");
     imageN         = image.GetComponent <Image>();
     bunrui         = syousaiPanel.transform.Find("Bunrui");
     bunruiText     = bunrui.GetComponent <Text>();
     henseiPanel    = transform.root.Find("HenseiPanel");
     hensei         = henseiPanel.GetComponent <Hensei>();
     //Debug.Log(handgunAniMesh[0]);
     //Debug.Log(rifleMesh);
     for (int i = 0; i < 5; i++)
     {
         playerItem[i] = Resources.Load <Anima2D.SpriteMesh>("SpriteMesh/PlayerItem/buki sozai" + (i + 1).ToString());
         //Debug.Log(playerItem[i]);
     }
 }
    protected void Start()
    {
        propertyBlock = new MaterialPropertyBlock();
        if (transform.Find("Sprite") != null)
        {
            if (transform.Find("Sprite").transform.Find("Body") != null)
            {
                spriteMeshInstance = transform.Find("Sprite").transform.Find("Body").GetComponent <Anima2D.SpriteMeshInstance>();
                Material mat = Instantiate(spriteMeshInstance.GetComponent <Anima2D.SpriteMeshInstance>().sharedMaterial);
                //skinnedMeshRenderer.material = mat;
                spriteMeshInstance.GetComponent <Anima2D.SpriteMeshInstance>().sharedMaterial = mat;
            }
            liquidSprite = transform.Find("Sprite").transform.Find("Liquid").GetComponent <SpriteRenderer>();
        }

        if (liquidSprite != null)
        {
            liquidSprite.color = phColorDictionary[Mathf.FloorToInt(phValue + 0.1f)];
        }
        else
        {
            PhTransitionMechanic = false;
        }

        //Checking for the sprite mesh renderer
        if (spriteMeshInstance != null)
        {
            spriteMeshInstance.GetComponent <Renderer>().GetPropertyBlock(propertyBlock);
            propertyBlock.SetColor("_Color", initialCharacterColor);
            spriteMeshInstance.GetComponent <Renderer>().SetPropertyBlock(propertyBlock);

            if (PhTransitionMechanic && revealpH)
            {
                Debug.Log("Changed color");
                spriteMeshInstance.sharedMaterial.SetColor("_LiquidColor", phColorDictionary[Mathf.FloorToInt(phValue + 0.1f)]);
            }
        }
    }
        void OnEnable()
        {
            m_SpriteMeshInstance     = target as SpriteMeshInstance;
            m_SortingOrder           = serializedObject.FindProperty("m_SortingOrder");
            m_SortingLayerID         = serializedObject.FindProperty("m_SortingLayerID");
            m_SpriteMeshProperty     = serializedObject.FindProperty("m_SpriteMesh");
            m_SpriteOverrideProperty = serializedObject.FindProperty("m_SpriteOverride");
            m_ColorProperty          = serializedObject.FindProperty("m_Color");
            m_MaterialsProperty      = serializedObject.FindProperty("m_Materials.Array");
            m_BonesProperty          = serializedObject.FindProperty("m_Bones.Array");
            m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms.Array");

            UpgradeToMaterials();
            UpgradeToBoneTransforms();

            /*
             * if(m_SpriteMeshInstance.cachedRenderer)
             * {
             *      foreach(Material material in m_SpriteMeshInstance.cachedRenderer.sharedMaterials)
             *      {
             *              if(material)
             *              {
             *                      material.hideFlags = HideFlags.HideInInspector;
             *              }
             *      }
             * }
             */

            UpdateSpriteMeshData();
            SetupBoneList();

#if UNITY_5_5_OR_NEWER
#else
            EditorUtility.SetSelectedWireframeHidden(m_SpriteMeshInstance.cachedRenderer, !m_SpriteMeshInstance.cachedSkinnedRenderer);
#endif
        }
        void OnEnable()
        {
            mSpriteMeshInstance = target as SpriteMeshInstance;

            SetupList();
        }
Esempio n. 23
0
		static int FindBindInfo(BindInfo bindInfo, SpriteMeshInstance spriteMeshInstance)
		{
			if(spriteMeshInstance)
			{
				return FindBindInfo(bindInfo, SpriteMeshUtils.LoadSpriteMeshData(spriteMeshInstance.spriteMesh));

			}

			return -1;
		}
Esempio n. 24
0
		public static void UpdateRenderer(SpriteMeshInstance spriteMeshInstance, bool undo = true)
		{
			if(!spriteMeshInstance)
			{
				return;
			}
			
			SerializedObject spriteMeshInstaceSO = new SerializedObject(spriteMeshInstance);
			
			SpriteMesh spriteMesh = spriteMeshInstaceSO.FindProperty("m_SpriteMesh").objectReferenceValue as SpriteMesh;
			
			if(spriteMesh)
			{
				Material[] materials = spriteMesh.sharedMaterials;
				Mesh sharedMesh = spriteMesh.sharedMesh;
				
				if(sharedMesh.bindposes.Length > 0 && spriteMeshInstance.bones.Count > sharedMesh.bindposes.Length)
				{
					spriteMeshInstance.bones = spriteMeshInstance.bones.GetRange(0,sharedMesh.bindposes.Length);
				}
				
				if(CanEnableSkinning(spriteMeshInstance))
				{
					MeshFilter meshFilter = spriteMeshInstance.cachedMeshFilter;
					MeshRenderer meshRenderer = spriteMeshInstance.cachedRenderer as MeshRenderer;
					
					if(meshFilter)
					{
						if(undo)
						{
							Undo.DestroyObjectImmediate(meshFilter);
						}else{
							GameObject.DestroyImmediate(meshFilter);
						}
					}
					if(meshRenderer)
					{
						if(undo)
						{
							Undo.DestroyObjectImmediate(meshRenderer);
						}else{
							GameObject.DestroyImmediate(meshRenderer);
						}
					}
					
					SkinnedMeshRenderer skinnedMeshRenderer = spriteMeshInstance.cachedSkinnedRenderer;
					
					if(!skinnedMeshRenderer)
					{
						if(undo)
						{
							skinnedMeshRenderer = Undo.AddComponent<SkinnedMeshRenderer>(spriteMeshInstance.gameObject);
						}else{
							skinnedMeshRenderer = spriteMeshInstance.gameObject.AddComponent<SkinnedMeshRenderer>();
						}
					}
					
					skinnedMeshRenderer.sharedMesh = spriteMesh.sharedMesh;
					skinnedMeshRenderer.bones = spriteMeshInstance.bones.ConvertAll( bone => bone.transform ).ToArray();
					
					if(spriteMeshInstance.bones.Count > 0)
					{
						skinnedMeshRenderer.rootBone = spriteMeshInstance.bones[0].transform;
					}
					
					skinnedMeshRenderer.sharedMaterials = materials;
					skinnedMeshRenderer.sharedMesh = sharedMesh;
					
					EditorUtility.SetDirty(skinnedMeshRenderer);
				}else{
					SkinnedMeshRenderer skinnedMeshRenderer = spriteMeshInstance.cachedSkinnedRenderer;
					MeshFilter meshFilter = spriteMeshInstance.cachedMeshFilter;
					MeshRenderer meshRenderer = spriteMeshInstance.cachedRenderer as MeshRenderer;
					
					if(skinnedMeshRenderer)
					{
						if(undo)
						{
							Undo.DestroyObjectImmediate(skinnedMeshRenderer);
						}else{
							GameObject.DestroyImmediate(skinnedMeshRenderer);
						}
					}
					
					if(!meshFilter)
					{
						if(undo)
						{
							meshFilter = Undo.AddComponent<MeshFilter>(spriteMeshInstance.gameObject);
						}else{
							meshFilter = spriteMeshInstance.gameObject.AddComponent<MeshFilter>();
						}
						meshFilter.sharedMesh = sharedMesh;
						
						EditorUtility.SetDirty(meshFilter);
					}
					
					if(meshFilter)
					{
						meshFilter.sharedMesh = spriteMesh.sharedMesh;
					}
					
					if(!meshRenderer)
					{
						if(undo)
						{
							meshRenderer = Undo.AddComponent<MeshRenderer>(spriteMeshInstance.gameObject);
						}else{
							meshRenderer = spriteMeshInstance.gameObject.AddComponent<MeshRenderer>();
						}
						meshRenderer.sharedMaterials = materials;
						
						EditorUtility.SetDirty(meshRenderer);
					}
				}
			}
		}
Esempio n. 25
0
		public static bool CanEnableSkinning(SpriteMeshInstance spriteMeshInstance)
		{
			return spriteMeshInstance.spriteMesh && !HasNullBones(spriteMeshInstance) && spriteMeshInstance.bones.Count > 0 && (spriteMeshInstance.spriteMesh.sharedMesh.bindposes.Length == spriteMeshInstance.bones.Count);
		}
Esempio n. 26
0
		public static bool HasNullBones(SpriteMeshInstance spriteMeshInstance)
		{
			if(spriteMeshInstance)
			{
				return spriteMeshInstance.bones.Contains(null);
			}
			return false;
		}
Esempio n. 27
0
		static bool Bindeable(SpriteMeshInstance targetSpriteMeshInstance, SpriteMeshInstance destinationSpriteMeshInstance)
		{
			bool bindeable = false;

			if(targetSpriteMeshInstance &&
			   destinationSpriteMeshInstance &&
			   targetSpriteMeshInstance.spriteMesh &&
			   destinationSpriteMeshInstance.spriteMesh &&
			   targetSpriteMeshInstance.spriteMesh != destinationSpriteMeshInstance.spriteMesh &&
			   destinationSpriteMeshInstance.cachedSkinnedRenderer)
			{
				SpriteMeshData targetData = SpriteMeshUtils.LoadSpriteMeshData(targetSpriteMeshInstance.spriteMesh);
				SpriteMeshData destinationData = SpriteMeshUtils.LoadSpriteMeshData(destinationSpriteMeshInstance.spriteMesh);

				bindeable = true;

				if(destinationData.bindPoses.Length >= targetData.bindPoses.Length)
				{
					for(int i = 0; i < targetData.bindPoses.Length; ++i)
					{
						if(bindeable)
						{
							BindInfo bindInfo = targetData.bindPoses[i];

							if(FindBindInfo(bindInfo,destinationData) < 0)
							{
								bindeable = false;
							}
						}
					}
				}else{
					bindeable = false;
				}	
			}
			return bindeable;
		}
Esempio n. 28
0
        static void HandleDragAndDrop(bool createOnEnter, Transform parent)
        {
            switch (Event.current.type)
            {
            case EventType.DragUpdated:

                if (!init)
                {
                    spriteMesh = GetSpriteMesh();

                    if (createOnEnter)
                    {
                        parentTransform = null;
                        CreateInstance();
                    }

                    Event.current.Use();

                    init = true;
                }

                if (instance)
                {
                    instance.transform.position = instancePosition;

                    SpriteMeshInstance l_currentDestination = GetClosestBindeableIntersectingSpriteMeshInstance();

                    if (currentDestination != l_currentDestination)
                    {
                        currentDestination = l_currentDestination;

                        if (currentDestination)
                        {
                            List <Bone2D> destinationBones = currentDestination.bones;
                            List <Bone2D> newBones         = new List <Bone2D>();

                            SpriteMeshData data = SpriteMeshUtils.LoadSpriteMeshData(instance.spriteMesh);

                            for (int i = 0; i < data.bindPoses.Length; ++i)
                            {
                                BindInfo bindInfo = data.bindPoses[i];
                                int      index    = FindBindInfo(bindInfo, currentDestination);
                                if (index >= 0 && index < destinationBones.Count)
                                {
                                    newBones.Add(destinationBones[index]);
                                }
                            }

                            instance.transform.parent = currentDestination.transform.parent;
                            instance.bones            = newBones;
                            SpriteMeshUtils.UpdateRenderer(instance, false);

                            foreach (Bone2D bone in s_InstanceBones)
                            {
                                bone.hideFlags = HideFlags.HideAndDontSave;
                                bone.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            foreach (Bone2D bone in s_InstanceBones)
                            {
                                bone.hideFlags = HideFlags.None;
                                bone.gameObject.SetActive(true);
                            }

                            instance.transform.parent = null;
                            instance.bones            = s_InstanceBones;
                            SpriteMeshUtils.UpdateRenderer(instance, false);
                        }

                        SceneView.RepaintAll();
                    }
                }

                break;

            case EventType.DragExited:

                if (instance)
                {
                    GameObject.DestroyImmediate(instance.gameObject);
                    Event.current.Use();
                }

                Cleanup();
                break;

            case EventType.DragPerform:

                if (!createOnEnter)
                {
                    CreateInstance();
                }

                if (instance)
                {
                    if (currentDestination)
                    {
                        foreach (Bone2D bone in s_InstanceBones)
                        {
                            if (bone)
                            {
                                GameObject.DestroyImmediate(bone.gameObject);
                            }
                        }
                    }

                    Undo.RegisterCreatedObjectUndo(instance.gameObject, "create SpriteMeshInstance");
                }

                Cleanup();
                break;
            }

            if (instance)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            }
        }
Esempio n. 29
0
 public static bool CanEnableSkinning(SpriteMeshInstance spriteMeshInstance)
 {
     return(spriteMeshInstance.spriteMesh && !HasNullBones(spriteMeshInstance) && spriteMeshInstance.bones.Count > 0 && (spriteMeshInstance.spriteMesh.sharedMesh.bindposes.Length == spriteMeshInstance.bones.Count));
 }
Esempio n. 30
0
		static void HandleDragAndDrop(bool createOnEnter, Transform parent)
		{
			switch(Event.current.type)
			{
			case EventType.DragUpdated:

				if(!init)
				{
					spriteMesh = GetSpriteMesh();

					if(createOnEnter)
					{
						parentTransform = null;
						CreateInstance();
					}

					Event.current.Use();

					init = true;
				}

				if(instance)
				{
					instance.transform.position = instancePosition;

					SpriteMeshInstance l_currentDestination = GetClosestBindeableIntersectingSpriteMeshInstance();

					if(currentDestination != l_currentDestination)
					{
						currentDestination = l_currentDestination;

						if(currentDestination)
						{
							List<Bone2D> destinationBones = currentDestination.bones;
							List<Bone2D> newBones = new List<Bone2D>();

							SpriteMeshData data = SpriteMeshUtils.LoadSpriteMeshData(instance.spriteMesh);

							for(int i = 0; i < data.bindPoses.Length; ++i)
							{
								BindInfo bindInfo = data.bindPoses[i];
								int index = FindBindInfo(bindInfo,currentDestination);
								if(index >= 0)
								{
									newBones.Add(destinationBones[index]);
								}
							}

							instance.transform.parent = currentDestination.transform.parent;
							instance.bones = newBones;
							SpriteMeshUtils.UpdateRenderer(instance,false);

							foreach(Bone2D bone in s_InstanceBones)
							{
								bone.hideFlags = HideFlags.HideAndDontSave;
								bone.gameObject.SetActive(false);
							}

						}else{
							foreach(Bone2D bone in s_InstanceBones)
							{
								bone.hideFlags = HideFlags.None;
								bone.gameObject.SetActive(true);
							}

							instance.transform.parent = null;
							instance.bones = s_InstanceBones;
							SpriteMeshUtils.UpdateRenderer(instance,false);
						}

						SceneView.RepaintAll();
					}
				}

				break;
			
			case EventType.DragExited:

				if(instance)
				{
					GameObject.DestroyImmediate(instance.gameObject);
					Event.current.Use();
				}
				Cleanup();
				break;

			case EventType.DragPerform:

				if(!createOnEnter)
				{
					CreateInstance();
				}

				if(instance)
				{
					if(currentDestination)
					{
						foreach(Bone2D bone in s_InstanceBones)
						{
							if(bone)
							{
								GameObject.DestroyImmediate(bone.gameObject);
							}
						}
					}

					Undo.RegisterCreatedObjectUndo(instance.gameObject,"create SpriteMeshInstance");
				}

				Cleanup();
				break;
			}

			if(instance)
			{
				DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
			}
		}
Esempio n. 31
0
		public void SetSpriteMesh(SpriteMesh _spriteMesh, SpriteMeshInstance _spriteMeshInstance)
		{
			spriteMesh = _spriteMesh;
			spriteMeshInstance = _spriteMeshInstance;
			spriteMeshData = SpriteMeshUtils.LoadSpriteMeshData(_spriteMesh);
			RevertChanges();
		}
Esempio n. 32
0
        public static void UpdateRenderer(SpriteMeshInstance spriteMeshInstance, bool undo = true)
        {
            if (!spriteMeshInstance)
            {
                return;
            }

            SerializedObject spriteMeshInstaceSO = new SerializedObject(spriteMeshInstance);

            SpriteMesh spriteMesh = spriteMeshInstaceSO.FindProperty("m_SpriteMesh").objectReferenceValue as SpriteMesh;

            if (spriteMesh)
            {
                Mesh sharedMesh = spriteMesh.sharedMesh;

                if (sharedMesh.bindposes.Length > 0 && spriteMeshInstance.bones.Count > sharedMesh.bindposes.Length)
                {
                    spriteMeshInstance.bones = spriteMeshInstance.bones.GetRange(0, sharedMesh.bindposes.Length);
                }

                if (CanEnableSkinning(spriteMeshInstance))
                {
                    MeshFilter   meshFilter   = spriteMeshInstance.cachedMeshFilter;
                    MeshRenderer meshRenderer = spriteMeshInstance.cachedRenderer as MeshRenderer;

                    if (meshFilter)
                    {
                        if (undo)
                        {
                            Undo.DestroyObjectImmediate(meshFilter);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(meshFilter);
                        }
                    }
                    if (meshRenderer)
                    {
                        if (undo)
                        {
                            Undo.DestroyObjectImmediate(meshRenderer);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(meshRenderer);
                        }
                    }

                    SkinnedMeshRenderer skinnedMeshRenderer = spriteMeshInstance.cachedSkinnedRenderer;

                    if (!skinnedMeshRenderer)
                    {
                        if (undo)
                        {
                            skinnedMeshRenderer = Undo.AddComponent <SkinnedMeshRenderer>(spriteMeshInstance.gameObject);
                        }
                        else
                        {
                            skinnedMeshRenderer = spriteMeshInstance.gameObject.AddComponent <SkinnedMeshRenderer>();
                        }
                    }

                    skinnedMeshRenderer.bones = spriteMeshInstance.bones.ConvertAll(bone => bone.transform).ToArray();

                    if (spriteMeshInstance.bones.Count > 0)
                    {
                        skinnedMeshRenderer.rootBone = spriteMeshInstance.bones[0].transform;
                    }

                    EditorUtility.SetDirty(skinnedMeshRenderer);
                }
                else
                {
                    SkinnedMeshRenderer skinnedMeshRenderer = spriteMeshInstance.cachedSkinnedRenderer;
                    MeshFilter          meshFilter          = spriteMeshInstance.cachedMeshFilter;
                    MeshRenderer        meshRenderer        = spriteMeshInstance.cachedRenderer as MeshRenderer;

                    if (skinnedMeshRenderer)
                    {
                        if (undo)
                        {
                            Undo.DestroyObjectImmediate(skinnedMeshRenderer);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(skinnedMeshRenderer);
                        }
                    }

                    if (!meshFilter)
                    {
                        if (undo)
                        {
                            meshFilter = Undo.AddComponent <MeshFilter>(spriteMeshInstance.gameObject);
                        }
                        else
                        {
                            meshFilter = spriteMeshInstance.gameObject.AddComponent <MeshFilter>();
                        }

                        EditorUtility.SetDirty(meshFilter);
                    }

                    if (!meshRenderer)
                    {
                        if (undo)
                        {
                            meshRenderer = Undo.AddComponent <MeshRenderer>(spriteMeshInstance.gameObject);
                        }
                        else
                        {
                            meshRenderer = spriteMeshInstance.gameObject.AddComponent <MeshRenderer>();
                        }

                        EditorUtility.SetDirty(meshRenderer);
                    }
                }
            }
        }
Esempio n. 33
0
 // Use this for initialization
 void Start()
 {
     mesh   = GetComponent <Anima2D.SpriteMeshInstance>();
     sprite = GetComponent <SpriteRenderer>();
 }