Ejemplo n.º 1
0
    public void Unregister(GPUSkinAnimation anim)
    {
        if (anim == null)
        {
            return;
        }

        GPUSkinAnimationItem item = null;

        if (!allAnimations.TryGetValue(anim.AnimationData, out item))
        {
            return;
        }

        anim.Texture = null;
        item.animations.Remove(anim);

        if (item.animations.Count == 0)
        {
            UnityEngine.Object.DestroyImmediate(item.texture);
            item.texture = null;

            allAnimations.Remove(anim.AnimationData);
        }
    }
Ejemplo n.º 2
0
 public Color[] GetColors(GPUSkinAnimation anim)
 {
     if (allAnimations.TryGetValue(anim.AnimationData, out GPUSkinAnimationItem item))
     {
         return(item.pixels);
     }
     return(null);
 }
Ejemplo n.º 3
0
 public bool IsDeviceLost(GPUSkinAnimation anim, float time)
 {
     if (allAnimations.TryGetValue(anim.AnimationData, out GPUSkinAnimationItem item))
     {
         if (item.time != time)
         {
             item.time = time;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        animator  = GetComponent <Animator>();
        animation = GetComponent <GPUSkinAnimation>();

        if (animator != null)
        {
            animator.Play("walk");
        }
        else
        {
            animation.Play("walk");
        }
    }
Ejemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        GPUSkinAnimation animation = target as GPUSkinAnimation;

        if (animation == null)
        {
            return;
        }

        EditorGUILayout.PropertyField(serializedObject.FindProperty("animData"));

        EditorGUILayout.PropertyField(serializedObject.FindProperty("mesh"));

        EditorGUILayout.PropertyField(serializedObject.FindProperty("material"));

        EditorGUILayout.PropertyField(serializedObject.FindProperty("cullingMode"), new GUIContent("Culling Mode"));

        EditorGUILayout.PropertyField(serializedObject.FindProperty("rootMotionEnabled"), new GUIContent("Apply Root Motion"));

        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 6
0
    public void Register(GPUSkinAnimation anim)
    {
        if (anim == null)
        {
            return;
        }

        GPUSkinAnimationItem item = null;

        if (!allAnimations.TryGetValue(anim.AnimationData, out item))
        {
            item = new GPUSkinAnimationItem();
            allAnimations.Add(anim.AnimationData, item);
        }
        item.animations.Add(anim);

        if (item.texture == null)
        {
            item.texture = GPUSkinUtil.CreateTexture2D(anim.AnimationData);
        }

        anim.Texture = item.texture;
    }
Ejemplo n.º 7
0
    private void OnPreview(GPUSkinGenerator gen)
    {
        BeginBox();
        {
            if (GUILayout.Button("Preview And Edit"))
            {
                animData        = gen.animData;
                mesh            = gen.savedMesh;
                previewMaterial = gen.previewMaterial;

                if (animData == null || mesh == null || previewMaterial == null)
                {
                    EditorUtility.DisplayDialog("GPUSkin", "Missing Preview Resources", "OK");
                }
                else
                {
                    if (previewRenderTexture == null && !EditorApplication.isPlaying)
                    {
                        previewRenderTexture           = new RenderTexture(1024, 1024, 32, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
                        previewRenderTexture.hideFlags = HideFlags.HideAndDontSave;

                        GameObject cameroGo = new GameObject("GPUSkinEditorCameraGo");
                        cameroGo.hideFlags               = HideFlags.HideAndDontSave;
                        previewCamera                    = cameroGo.AddComponent <Camera>();
                        previewCamera.hideFlags          = HideFlags.HideAndDontSave;
                        previewCamera.farClipPlane       = 100;
                        previewCamera.targetTexture      = previewRenderTexture;
                        previewCamera.enabled            = false;
                        previewCamera.clearFlags         = CameraClearFlags.SolidColor;
                        previewCamera.backgroundColor    = new Color(0.2f, 0.2f, 0.2f, 1.0f);
                        previewCamera.transform.position = new Vector3(999, 1002, 999);

                        GameObject previewGo = new GameObject("GPUSkinEditorPreviewGo");
                        previewGo.hideFlags          = HideFlags.HideAndDontSave;
                        previewGo.transform.position = new Vector3(999, 999, 1002);
                        previewAnimation             = previewGo.AddComponent <GPUSkinAnimation>();
                        previewAnimation.hideFlags   = HideFlags.HideAndDontSave;
                        previewAnimation.Init(animData, mesh, previewMaterial);
                        previewAnimation.CullingMode = GPUSkinCullingMode.AlwaysAnimate;
                    }
                }
            }

            GetLastGUIRect(ref previewEditBtnRect);

            if (previewRenderTexture != null)
            {
                int previewRectSize = Mathf.Min((int)(previewEditBtnRect.width * 0.98f), 512);
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical();
                    {
                        GUILayout.Box(previewRenderTexture, GUILayout.Width(previewRectSize), GUILayout.Height(previewRectSize));


                        GetLastGUIRect(ref previewInteractionRect);
                        PreviewInteraction(previewInteractionRect);

                        EditorGUILayout.HelpBox("Drag to Orbit\nCtrl + Drag to Pitch\nAlt+ Drag to Zoom\nPress P Key to Pause", MessageType.None);
                    }
                    EditorGUILayout.EndVertical();

                    //EditorGUI.ProgressBar(new Rect(previewInteractionRect.x, previewInteractionRect.y + previewInteractionRect.height, previewInteractionRect.width, 5), previewAnimation.NormalizedTime, string.Empty);
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        EndBox();

        serializedObject.ApplyModifiedProperties();
    }