Esempio n. 1
0
    private void OnEnable()
    {
        if (hitboxBackgroundStyle == null)
        {
            hitboxBackgroundStyle = new GUIStyle();
            hitboxBackgroundStyle.normal.background = MakeTexture(1, 1, new Color(0f, 0f, 0f, 0.2f));
        }
        //When changing scenes the background is deleted
        else if (hitboxBackgroundStyle.normal.background == null)
        {
            hitboxBackgroundStyle.normal.background = MakeTexture(1, 1, new Color(0f, 0f, 0f, 0.2f));
        }

        targetComponents = target as HitBoxComponent;
        AnimationHelper.init();

        targetComponents.SyncKeyFramesWithSimpleAnimator();

        if (targetComponents.inspectorTemp != null)
        {
            var state = targetComponents.GetState(targetComponents.GetStateNames()[targetComponents.inspectorTemp.animationindex]);
            AnimationHelper.SetCurrentClip(state.clip);
            traceAnimMode = (TraceAnimMode)targetComponents.inspectorTemp.traceAnimMode;
        }
    }
Esempio n. 2
0
    private void DrawHitboxes()
    {
        traceAnimMode = (TraceAnimMode)EditorGUILayout.Popup("trace Animation Mode", (int)traceAnimMode, new string[] { "Off", "AnimationWindow", "Scene(PlayOnly)" });
        targetComponents.inspectorTemp.traceAnimMode = (int)traceAnimMode;
        if (traceAnimMode == TraceAnimMode.AnimationWindow)
        {
            var currentFrame = AnimationHelper.GetCurrentFrame();
            targetComponents.inspectorTemp.keyframeIndex = currentFrame;


            var AnimGuiClipname   = AnimationHelper.GetCurrentClipName();
            var preanimationindex = targetComponents.inspectorTemp.animationindex;
            targetComponents.inspectorTemp.animationindex = EditorGUILayout.Popup("AnimStateName", targetComponents.inspectorTemp.animationindex, targetComponents.GetStateNames().ToArray());
            var selectedStateName = targetComponents.GetStateNames()[targetComponents.inspectorTemp.animationindex];
            var selectedState     = targetComponents.GetState(selectedStateName);
            if (AnimGuiClipname != selectedState.clip.name)
            {
                AnimationHelper.SetCurrentClip(selectedState.clip);
                Debug.Log("From HitBoxComponent: Now AnimationWindow is synchronized with HitBoxComponent. If you want to change AnimationClip of AnimationWindow, turn \"TraceAnimMode\" off on HitBoxComponent Inspector");
            }
            EditorGUILayout.LabelField("Clipname", selectedState.clip.name);

            if (targetComponents.inspectorTemp.keyframeIndex >= targetComponents.hitboxes[selectedStateName].keyframes.Count)
            {
                return;
            }
            ;
        }
        if (traceAnimMode == TraceAnimMode.Scene)
        {
            if (!Application.isPlaying)
            {
                return;
            }
            var currentFrame = targetComponents.GetNowKeyFrame();
            targetComponents.inspectorTemp.keyframeIndex = currentFrame;
            var nowstate = targetComponents.GetNowState();
            EditorGUILayout.LabelField("NowStateName", nowstate.name);
            targetComponents.inspectorTemp.animationindex = targetComponents.GetStateNames().FindIndex(e => e == nowstate.name);
            EditorGUILayout.LabelField("Clipname", nowstate.clip.name);
        }
        if (traceAnimMode == TraceAnimMode.Off)
        {
            targetComponents.inspectorTemp.animationindex = EditorGUILayout.Popup("AnimStateName", targetComponents.inspectorTemp.animationindex, targetComponents.GetStateNames().ToArray());
            var statename = targetComponents.GetStateNames()[targetComponents.inspectorTemp.animationindex];
            EditorGUILayout.LabelField("ClipName", targetComponents.GetClipName(statename));
        }

        EditorGUILayout.LabelField("Flip", targetComponents.direction.ToString());

        if (Application.isPlaying && traceAnimMode == TraceAnimMode.Off)
        {
            if (GUILayout.Button("Show Now KeyFrame Data"))
            {
                var nowanim  = targetComponents.GetNowStateName();
                var keyframe = targetComponents.GetNowKeyFrame();
                targetComponents.inspectorTemp.animationindex = targetComponents.GetStateNames().FindIndex(0, e => e == nowanim);
                targetComponents.inspectorTemp.keyframeIndex  = keyframe;
            }
        }

        var animname = targetComponents.GetStateNames()[targetComponents.inspectorTemp.animationindex];

        var keyframenum = targetComponents.hitboxes[animname].keyframes.Count;

        targetComponents.inspectorTemp.keyframeIndex = EditorGUILayout.Popup("KeyFrameIndex", targetComponents.inspectorTemp.keyframeIndex, Enumerable.Range(0, keyframenum).Select(e => e.ToString() + (targetComponents.hitboxes[animname].keyframes[e].colliders.Count > 0 ? " *" : "")).ToArray());
        if (traceAnimMode == TraceAnimMode.AnimationWindow)
        {
            AnimationHelper.SetCurrentFrame(targetComponents.inspectorTemp.keyframeIndex);
            AnimationHelper.RepaintOpenAnimationWindow();
        }

        var animationindex = targetComponents.inspectorTemp.animationindex;
        var keyframeIndex  = targetComponents.inspectorTemp.keyframeIndex;


        for (int i = 0; i < targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders.Count; i++)
        {
            GUILayout.BeginVertical(hitboxBackgroundStyle);
            GUILayout.Label("Hitbox " + i);

            var colliderdata = targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders[i];
            //collider info
            colliderdata.tag      = EditorGUILayout.TextField("tag", colliderdata.tag);
            colliderdata.layer    = EditorGUILayout.TextField("layer", colliderdata.layer);
            colliderdata.dulation = EditorGUILayout.IntField("dulation", colliderdata.dulation);
            colliderdata.data     = EditorGUILayout.TextField("data", colliderdata.data);

            //collider shape
            if (colliderdata.colliderParam == null)
            {
                colliderdata.colliderParam = CreateInstance <RectColliderParam>();
            }

            var selectedshape    = (ColliderShape)EditorGUILayout.EnumPopup(colliderdata.colliderParam.GetShape());
            var newcolliderparam = ColliderParam.ColliderParamFactory(selectedshape);

            if (newcolliderparam != null && colliderdata.colliderParam.GetShape() != selectedshape)
            {
                var path = AssetDatabase.GetAssetPath(targetComponents.hitboxes);
                AssetDatabase.RemoveObjectFromAsset(colliderdata.colliderParam);

                colliderdata.colliderParam = newcolliderparam;
                AssetDatabase.AddObjectToAsset(colliderdata.colliderParam, path);
                AssetDatabase.Refresh();
                AssetDatabase.ImportAsset(path);
            }

            DrawColliderParam(colliderdata.colliderParam);

            EditorUtility.SetDirty(colliderdata.colliderParam);


            if (GUILayout.Button("Remove HitBox", GUILayout.Width(100)))
            {
                var path = AssetDatabase.GetAssetPath(targetComponents.hitboxes);
                AssetDatabase.RemoveObjectFromAsset(targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders[i].colliderParam);
                AssetDatabase.Refresh();
                AssetDatabase.ImportAsset(path);

                for (int j = i; j < targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders.Count - 1; j++)
                {
                    targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders[j] = targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders[j + 1];
                }

                targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders.RemoveAt(targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders.Count - 1);
                SceneView.RepaintAll();
            }
            GUILayout.EndVertical();


            //separate
            GUILayout.BeginVertical(GUILayout.Height(10));
            GUILayout.Label("", GUILayout.Height(10));
            GUILayout.EndVertical();
        }


        if (GUILayout.Button("Add Hitbox", GUILayout.Width(100)))
        {
            var addData = new KeyFrameCollider();
            addData.colliderParam = CreateInstance <RectColliderParam>();
            addData.startframe    = keyframeIndex;
            targetComponents.hitboxes[animname].keyframes[keyframeIndex].colliders.Add(addData);

            SceneView.RepaintAll();

            var path = AssetDatabase.GetAssetPath(targetComponents.hitboxes);
            AssetDatabase.AddObjectToAsset(addData.colliderParam, path);

            //インポート処理を走らせて最新の状態にする
            AssetDatabase.Refresh();
            AssetDatabase.ImportAsset(path);
        }
    }