Exemplo n.º 1
0
 private static IEnumerator FadeOutCoroutine(SpriteMeshInstance mesh, float duration)
 {
     while (mesh != null && mesh.color.a > 0)
     {
         var color = mesh.color;
         color.a   -= Time.deltaTime / duration;
         mesh.color = color;
         yield return(null);
     }
 }
Exemplo n.º 2
0
    public MosquitoBloodSuck(MosquitoHandler p_mosquito, SpriteMeshInstance p_body_sprite)
    {
        _mosquito   = p_mosquito;
        _bodySprite = p_body_sprite;

        d_speed        = p_mosquito.speed;
        d_rotate_speed = p_mosquito.rotateSpeed;

        _bodySprite.transform.localScale = Vector3.one;
        _mosquito.OnStatusChange        += OnStatusChange;
    }
Exemplo n.º 3
0
        private static IEnumerator FadeInCoroutine(SpriteMeshInstance mesh, float duration)
        {
            mesh.color = mesh.color.With(a: 0);

            while (mesh != null && mesh.color.a < 1)
            {
                var color = mesh.color;
                color.a   += Time.deltaTime / duration;
                mesh.color = color;
                yield return(null);
            }
        }
        public static void SavePose(Skin skin, Transform root)
        {
            List <SpriteMeshInstance> skins = new List <SpriteMeshInstance>(50);

            root.GetComponentsInChildren <SpriteMeshInstance>(true, skins);

            SerializedObject   skin0s      = new SerializedObject(skin);
            SerializedProperty entriesProp = skin0s.FindProperty("m_SkinEntries");


            skin0s.Update();
            entriesProp.arraySize = skins.Count;

            for (int i = 0; i < skins.Count; i++)
            {
                SpriteMeshInstance spriteMeshInstance = skins[i];

                if (spriteMeshInstance)
                {
                    SerializedProperty element = entriesProp.GetArrayElementAtIndex(i);
                    element.FindPropertyRelative("path").stringValue          = SpriteMeshUtils.GetSpriteMeshPath(root, spriteMeshInstance);
                    element.FindPropertyRelative("skin").objectReferenceValue = spriteMeshInstance.spriteMesh;
                }
            }

            skin0s.ApplyModifiedProperties();
            List <SpriteMesh> faces = new List <SpriteMesh>(50);

            faces.AddRange(root.GetComponentInChildren <SpriteMeshAnimation>().frames);

            SerializedObject   face0s       = new SerializedObject(skin);
            SerializedProperty entriesProp1 = face0s.FindProperty("m_FaceEntries");


            face0s.Update();
            entriesProp1.arraySize = faces.Count;
            for (int i = 0; i < faces.Count; i++)
            {
                SpriteMesh faceMesh = faces[i];

                if (faceMesh)
                {
                    SerializedProperty element = entriesProp1.GetArrayElementAtIndex(i);
                    element.FindPropertyRelative("path").stringValue          = SpriteMeshUtils.GetSpriteMeshPath(root, root.GetComponentInChildren <SpriteMeshAnimation>());
                    element.FindPropertyRelative("skin").objectReferenceValue = faceMesh;
                }
            }



            face0s.ApplyModifiedProperties();
        }
Exemplo n.º 5
0
        private static SpriteMesh GenerateSpriteMesh(Sprite sprite)
        {
            SpriteMesh spriteMesh = SpriteMeshUtils.CreateSpriteMesh(sprite);

            SpriteMeshInstance spriteMeshInstance = SpriteMeshUtils.CreateSpriteMeshInstance(spriteMesh, Selection.activeGameObject, true);

            SpriteMeshCache spriteMeshCache = ScriptableObject.CreateInstance <SpriteMeshCache>();

            spriteMeshCache.SetSpriteMesh(spriteMesh, spriteMeshInstance);
            spriteMeshCache.InitFromOutline(0.25f, 0.05f, true, 0.1f, "set outline");
            spriteMeshCache.ApplyChanges();

            return(spriteMesh);
        }
Exemplo n.º 6
0
 // Start is called before the first frame update
 private void Awake()
 {
     if (_specialMesh)
     {
         _meshInstance = gameObject.GetComponent <SpriteMeshInstance>();
     }
     else if (_particle)
     {
         _particleRendeder = gameObject.GetComponent <ParticleSystemRenderer>();
     }
     else
     {
         myRenderer = gameObject.GetComponent <Renderer>();
     }
 }
Exemplo n.º 7
0
    /// <summary>
    /// UpdateSpriteMeshes
    /// Updates the sprite mesh of all skin targets in the given list.
    /// </summary>
    /// <param name="cpList">List of meshes to update</param>
    private void UpdateSpriteMeshes(List <CostumePiece> cpList)
    {
        // Loop through all costume parts in the costume's list
        foreach (CostumePiece cp in cpList)
        {
            Debug.Log(cp.GetSkinTarget());
            SpriteMeshInstance mesh = skeleton.Find(t => t.name == cp.GetSkinTarget());

            // If a mesh target is found, replace the sprite
            if (mesh)
            {
                mesh.spriteMesh = cp.GetSpriteMesh();
            }
        }
    }
Exemplo n.º 8
0
    void Start()
    {
        spriteRenderer     = GetComponent <SpriteRenderer>();
        spriteMeshInstance = GetComponent <SpriteMeshInstance>();

        if (spriteRenderer != null)
        {
            startcolor = spriteRenderer.color;
        }

        if (spriteMeshInstance != null)
        {
            startcolor = spriteMeshInstance.color;
        }
    }
        public static void LoadPose(Skin skin, Transform root)
        {
            SerializedObject   skinSO      = new SerializedObject(skin);
            SerializedProperty entriesProp = skinSO.FindProperty("m_SkinEntries");

            List <Skin> skins = new List <Skin>();

            for (int i = 0; i < entriesProp.arraySize; i++)
            {
                SerializedProperty element = entriesProp.GetArrayElementAtIndex(i);

                Transform skinTransform = root.Find(element.FindPropertyRelative("path").stringValue);

                if (skinTransform)
                {
                    SpriteMeshInstance skinComponent = skinTransform.GetComponent <SpriteMeshInstance>();

                    Undo.RecordObject(skinTransform.GetComponent <SpriteMeshInstance>(), "Load Skin");
                    skinComponent.spriteMesh = element.FindPropertyRelative("skin").objectReferenceValue as SpriteMesh;
                }
            }

            SerializedProperty entriesProp1 = skinSO.FindProperty("m_FaceEntries");

            List <SpriteMesh> faces = new List <SpriteMesh>();

            for (int i = 0; i < entriesProp1.arraySize; i++)
            {
                SerializedProperty element = entriesProp1.GetArrayElementAtIndex(i);
                faces.Add(element.FindPropertyRelative("skin").objectReferenceValue as SpriteMesh);
            }
            SpriteMeshAnimation sma = root.Find(entriesProp1.GetArrayElementAtIndex(0).FindPropertyRelative("path").stringValue).GetComponent <SpriteMeshAnimation>();

            if (faces.Count >= 1)
            {
                sma.frames = faces.ToArray();
                sma.frame  = 0;

                Undo.RecordObject(sma, "Load Skin");
            }
            EditorUtility.SetDirty(sma);
            //EditorUpdater.SetDirty("Load Skin");
        }
Exemplo n.º 10
0
    void Awake()
    {
        SpriteMeshInstance oldInstance = GetComponent <SpriteMeshInstance>();

        if (oldInstance)
        {
            SetSpriteMesh(oldInstance.spriteMesh);

            _bones = new Transform[oldInstance.bones.Count];
            for (int i = 0; i < oldInstance.bones.Count; ++i)
            {
                _bones[i] = oldInstance.bones[i].transform;
            }

            _sortingLayerID = oldInstance.sortingLayerID;
            _sortingOrder   = oldInstance.sortingOrder;

            DestroyImmediate(oldInstance);
        }
    }
Exemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        CustomizationManager.instance.OnSkinChanged.AddListener(SetSkinSV);
        CustomizationManager.instance.OnCostumeChanged.AddListener(CostumeChanged);

        HSVRangeMin = CustomizationManager.instance.GetHSVRangeMin();
        HSVRangeMax = CustomizationManager.instance.GetHSVRangeMax();

        // Creates instances of the HSV and default sprite materials to be applied at runtime as needed.
        skinMaterial   = new Material(Shader.Find("Custom/HSVRangeShader"));
        spriteMaterial = new Material(Shader.Find("Sprites/Default"));

        // Adjust HSV ranges
        skinMaterial.SetFloat("_HSVRangeMin", HSVRangeMin);
        skinMaterial.SetFloat("_HSVRangeMax", HSVRangeMax);

        // Find all sprite meshes attached to the player. This makes recoloring far easier.
        skeleton = PlayerMeshSkeleton.GetSkeleton();

        // Gets a reference to the player's head
        head = skeleton.Find(h => h.name == "Head");
        skinBodyParts.Add(head);

        // Determine the components that need to be recolored based on the costume.
        CostumeData costume = CustomizationManager.instance.GetCurrentCostume();

        if (costume != null)
        {
            List <string> costumeTargets = costume.GetSkinTargets();

            foreach (string s in costumeTargets)
            {
                AddSkinTarget(s);
            }
        }

        // Applies skin color
        SetSkinSV();
        ApplySkinColorToTargets();
    }
    //
    public void SetSortingLayer(MeshObjectElementForAnima2D meshElement)
    {
        if (meshElement != null && meshElement.meshObj != null)
        {
            Component element = meshElement.meshObj.GetComponent <SpriteMeshInstance>();
            if (element == null)
            {
                element = meshElement.meshObj.GetComponent <Renderer>();
            }

            int tagId = GetIdSubTagLayers(meshElement.soTag);

            if (tagId != -1 && tagId < slTagList.Count && slTagList.Count > 0)
            {
                int    newOrderID = GetSortingOrderByID(-tagId);
                string newName    = SortingLayer.layers[globalSortingLayerID].name;
                if (element is SpriteMeshInstance)
                {
                    SpriteMeshInstance smi = (SpriteMeshInstance)element;
                    smi.sortingLayerID   = newOrderID;
                    smi.sortingLayerName = newName;
                    smi.sortingOrder     = newOrderID;
                }
                else if (element is Renderer)
                {
                    Renderer r = (Renderer)element;
                    r.sortingLayerID   = SortingLayer.NameToID(newName);
                    r.sortingLayerName = newName;
                    r.sortingOrder     = newOrderID;
                }
                else if (element is SpriteRenderer)
                {
                    SpriteRenderer r = (SpriteRenderer)element;
                    r.sortingLayerID   = SortingLayer.NameToID(newName);
                    r.sortingLayerName = newName;
                    r.sortingOrder     = newOrderID;
                }
            }
        }
    }
Exemplo n.º 13
0
    void ReorderInLayers()
    {
        int order = (int)transform.position.z;
        int a     = 0;

        foreach (GameObject s in allParts)
        {
            SpriteRenderer sr = s.GetComponent <SpriteRenderer> ();
            if (sr)
            {
                sr.sortingOrder = (-100 * order) + orders [a];
            }
            else
            {
                SpriteMeshInstance smr = s.GetComponent <SpriteMeshInstance> ();
                if (smr)
                {
                    smr.sortingOrder = (-100 * order) + orders [a];
                }
            }
            a++;
        }
    }
Exemplo n.º 14
0
    void GetReferences()
    {
        rb           = GetComponent <Rigidbody2D>();
        anim         = GetComponent <Animator>();
        sounds       = GameObject.Find("Manager").GetComponent <SoundManager>();
        footOrigin   = transform.GetChild(0);
        frontOrigin  = transform.GetChild(1);
        backOrigin   = transform.GetChild(2);
        dizzyEffect  = transform.GetChild(5).gameObject;
        burstButtons = transform.GetChild(6).gameObject;
        burstButtons.GetComponent <DizzyButtons>().myPlayer  = this;
        burstButtons.GetComponent <DizzyButtons>().playerNum = playerNum;
        normalGrav = rb.gravityScale;
        respawnPos = transform.position;
        // Gets a reference to every mesh.
        GameObject meshSkeleton = transform.GetChild(3).gameObject;

        for (int i = 0; i < meshSkeleton.transform.childCount; i++)
        {
            GameObject         currentMesh = meshSkeleton.transform.GetChild(i).gameObject;
            SpriteMeshInstance smi         = currentMesh.GetComponent <SpriteMeshInstance>();
            meshes.Add(smi);
            if (i == 0)
            {
                sign = currentMesh.GetComponent <SpriteMeshAnimation>();
            }
            if (i == 1)
            {
                emblem = currentMesh.GetComponent <SpriteMeshAnimation>();
            }
        }
        impactAudio       = gameObject.AddComponent <AudioSource>();
        actionAudio       = gameObject.AddComponent <AudioSource>();
        loopingAudio      = gameObject.AddComponent <AudioSource>();
        loopingAudio.loop = true;
    }
Exemplo n.º 15
0
 public static string GetSpriteMeshPath(Transform root, SpriteMeshInstance spm)
 {
     return(GetPath(root, spm.transform));
 }
Exemplo n.º 16
0
        public GameObject Reconstruct(ImportLayerData root, ReconstructData data, GameObject selection)
        {
            GameObject rootObject = new GameObject(root.name);

            if (selection != null)
            {
                rootObject.transform.SetParent(selection.transform);
            }

            // Create a stack that represents the current parent
            // as the hierarchy is being traversed
            Stack <Transform> hierarchy = new Stack <Transform>();

            // Add the root object as the first parent
            hierarchy.Push(rootObject.transform);

            // Calculate the document pivot position
            Vector2 docRoot = data.documentSize;

            docRoot.x *= data.documentPivot.x;
            docRoot.y *= data.documentPivot.y;

            // Sorting index accumulator, so sprites draw in correct order
            int sortIdx = 0;

            root.Iterate(
                layer =>
            {
                // Only process non group layers and layers marked for import
                if (layer.Childs.Count > 0 || layer.import == false)
                {
                    return;
                }

                // Create an object
                GameObject layerObject = new GameObject(layer.name);
                Transform layerT       = layerObject.transform;
                // And attach it to the last
                layerT.SetParent(hierarchy.Peek());
                layerT.SetAsLastSibling();

                // Find the sprite for this layer in the data sprite index
                SpriteMesh spriteMesh;
                if (data.spriteMeshIndex.TryGetValue(layer.indexId, out spriteMesh))
                {
                    SpriteMeshInstance layerRender = SpriteMeshUtils.CreateSpriteMeshInstance(spriteMesh, layerObject, true);

                    layerRender.sortingOrder = sortIdx;
                    sortIdx--;
                }

                // Get the layer position
                Vector2 layerPos = GetLayerPosition(data, layer.indexId);
                // Express it as a vector
                Vector2 layerVector = layerPos - docRoot;
                // This is in pixel units, convert to unity world units
                layerVector    /= data.documentPPU;
                layerT.position = layerVector;
            },
                checkGroup => checkGroup.import,                 // Only enter groups if part of the import
                enterGroupCallback: layer =>
            {
                // Enter a group, create an object for it
                GameObject groupObject = new GameObject(layer.name);
                Transform groupT       = groupObject.transform;
                // Parent to the last hierarchy parent
                groupT.SetParent(hierarchy.Peek());
                // Look at me, I'm the hierarchy parent now
                hierarchy.Push(groupT);
            },
                exitGroupCallback: layer =>
            {
                // Go back to the last parent
                hierarchy.Pop();
            });

            // Unity 5.6 introduces the sorting group component
#if UNITY_5_6_OR_NEWER
            rootObject.AddComponent <SortingGroup>();
#endif
            return(rootObject);
        }
Exemplo n.º 17
0
    void Start()
    {
        Vector3 l_position = transform.position;
        Vector3 l_scale    = transform.localScale;

        transform.position   = Vector3.zero;
        transform.localScale = Vector3.one;

        List <Transform>       bones            = new List <Transform>();
        List <BoneWeight>      boneWeights      = new List <BoneWeight>();
        List <CombineInstance> combineInstances = new List <CombineInstance>();

        int numSubmeshes = 0;

        for (int i = 0; i < spriteMeshInstances.Length; i++)
        {
            SpriteMeshInstance spriteMeshInstance = spriteMeshInstances[i];

            if (spriteMeshInstance.cachedSkinnedRenderer)
            {
                numSubmeshes += spriteMeshInstance.mesh.subMeshCount;
            }
        }

        int[] meshIndex  = new int[numSubmeshes];
        int   boneOffset = 0;

        for (int i = 0; i < m_SpriteMeshInstances.Length; ++i)
        {
            SpriteMeshInstance spriteMeshInstance = spriteMeshInstances[i];

            if (spriteMeshInstance.cachedSkinnedRenderer)
            {
                SkinnedMeshRenderer skinnedMeshRenderer = spriteMeshInstance.cachedSkinnedRenderer;

                BoneWeight[] meshBoneweight = spriteMeshInstance.sharedMesh.boneWeights;

                // May want to modify this if the renderer shares bones as unnecessary bones will get added.
                for (int j = 0; j < meshBoneweight.Length; ++j)
                {
                    BoneWeight bw      = meshBoneweight[j];
                    BoneWeight bWeight = bw;
                    bWeight.boneIndex0 += boneOffset;
                    bWeight.boneIndex1 += boneOffset;
                    bWeight.boneIndex2 += boneOffset;
                    bWeight.boneIndex3 += boneOffset;
                    boneWeights.Add(bWeight);
                }

                boneOffset += spriteMeshInstance.bones.Count;

                Transform[] meshBones = skinnedMeshRenderer.bones;
                for (int j = 0; j < meshBones.Length; j++)
                {
                    Transform bone = meshBones[j];
                    bones.Add(bone);
                }

                CombineInstance combineInstance = new CombineInstance();
                Mesh            mesh            = new Mesh();
                skinnedMeshRenderer.BakeMesh(mesh);
                mesh.uv = spriteMeshInstance.spriteMesh.sprite.uv;
                combineInstance.mesh      = mesh;
                meshIndex[i]              = combineInstance.mesh.vertexCount;
                combineInstance.transform = skinnedMeshRenderer.localToWorldMatrix;
                combineInstances.Add(combineInstance);

                skinnedMeshRenderer.gameObject.SetActive(false);
            }
        }

        List <Matrix4x4> bindposes = new List <Matrix4x4>();

        for (int b = 0; b < bones.Count; b++)
        {
            bindposes.Add(bones[b].worldToLocalMatrix * transform.worldToLocalMatrix);
        }

        SkinnedMeshRenderer combinedSkinnedRenderer = gameObject.AddComponent <SkinnedMeshRenderer>();

        combinedSkinnedRenderer.sharedMesh = new Mesh();
        combinedSkinnedRenderer.sharedMesh.CombineMeshes(combineInstances.ToArray(), true, true);
        combinedSkinnedRenderer.bones = bones.ToArray();
        combinedSkinnedRenderer.sharedMesh.boneWeights = boneWeights.ToArray();
        combinedSkinnedRenderer.sharedMesh.bindposes   = bindposes.ToArray();
        combinedSkinnedRenderer.sharedMesh.RecalculateBounds();

        combinedSkinnedRenderer.materials = spriteMeshInstances[0].sharedMaterials;

        transform.position   = l_position;
        transform.localScale = l_scale;
    }
Exemplo n.º 18
0
 void Awake()
 {
     _spriteMeshInstance = GetComponent <SpriteMeshInstance>();
     _renderer           = GetComponent <SpriteRenderer>();
 }
Exemplo n.º 19
0
 public static void FadeIn(this SpriteMeshInstance mesh, float duration)
 {
     Timer.Instance.StartCoroutine(FadeInCoroutine(mesh, duration));
 }
 public void initialize()
 {
     sprMesh = this.GetComponent <SpriteMeshInstance>();
 }
Exemplo n.º 21
0
 void Awake()
 {
     si = GetComponent <SpriteMeshInstance>();
 }
Exemplo n.º 22
0
    static float BottomY(SpriteMeshInstance spriteRenderer)
    {
        Renderer renderer = spriteRenderer.GetComponent <Renderer>();

        return(renderer.bounds.center.y - renderer.bounds.extents.y);
    }