Beispiel #1
0
        private int GetFrameForHeadTurn(RoSpriteAnimator animator)
        {
            if (!animator.IsHead)
            {
                return(0);
            }

            if (HeadFacing == HeadFacing.Right)
            {
                return(1);
            }

            if (HeadFacing == HeadFacing.Left)
            {
                return(2);
            }

            return(0);
        }
Beispiel #2
0
        public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }
            if (Parent != null && !Parent.IsInitialized)
            {
                return;
            }
            if (gameObject == null)
            {
                return;
            }
            if (SpriteData == null)
            {
                return;
            }

            Type = SpriteData.Type;

            var parent = gameObject.transform.parent;

            if (parent == null)
            {
                //var bb = gameObject.AddComponent<Billboard>();
            }
            else
            {
                Parent = parent.gameObject.GetComponent <RoSpriteAnimator>();
                if (Parent != null)
                {
                    Controllable = Parent.Controllable;
                }
            }

            MeshFilter   = gameObject.AddComponent <MeshFilter>();
            MeshRenderer = gameObject.AddComponent <MeshRenderer>();

            MeshRenderer.sortingOrder = SpriteOrder;
            MeshCollider = gameObject.AddComponent <MeshCollider>();

            SortingGroup = gameObject.GetOrAddComponent <SortingGroup>();

            MeshRenderer.receiveShadows    = false;
            MeshRenderer.lightProbeUsage   = LightProbeUsage.Off;
            MeshRenderer.shadowCastingMode = ShadowCastingMode.Off;

            if (shader == null)
            {
                shader = Shader.Find("Unlit/TestSpriteShader");
            }

            if (shader == null)
            {
                Debug.LogError("Could not find shader Unlit/TestSpriteShader");
            }

            mat             = new Material(shader);
            mat.mainTexture = SpriteData.Atlas;

            SpriteData.Atlas.filterMode = !nextUseSmoothRender ? FilterMode.Bilinear : FilterMode.Point;

            if (Mathf.Approximately(0, SpriteOffset))
            {
                mat.SetFloat("_Offset", SpriteData.Size / 125f);
            }
            else
            {
                mat.SetFloat("_Offset", SpriteOffset);
            }

            MeshRenderer.material = mat;

            if (Parent != null)
            {
                mat.SetFloat("_Offset", Parent.SpriteData.Size / 125f);
            }

            if (AudioSource == null && Parent == null)
            {
                var channel = AudioManager.Instance.Mixer.FindMatchingGroups("Sounds")[0];
                AudioSource = gameObject.AddComponent <AudioSource>();
                AudioSource.spatialBlend          = 0.7f;
                AudioSource.priority              = 60;
                AudioSource.maxDistance           = 40;
                AudioSource.rolloffMode           = AudioRolloffMode.Linear;
                AudioSource.volume                = 1f;
                AudioSource.dopplerLevel          = 0;
                AudioSource.outputAudioMixerGroup = channel;
            }

            if (Type == SpriteType.Player && State == SpriteState.Idle)
            {
                isPaused = true;
            }

            if (ChildrenSprites.Count > 0)
            {
                foreach (var child in ChildrenSprites)
                {
                    child.Initialize();
                }
            }

            meshCache     = SpriteMeshCache.GetMeshCacheForSprite(SpriteData.Name);
            colliderCache = SpriteMeshCache.GetColliderCacheForSprite(SpriteData.Name);
            spriteName    = SpriteData.Name;

            Color = Color.white;
            Alpha = 1;

            isInitialized = true;

            ChangeMotion(CurrentMotion, true);

            if (parent == null)
            {
                UpdateShade();
                CurrentShade = TargetShade;                 //skip fade in at first spawn
            }

            isDirty = true;
        }