예제 #1
0
    private void BatchPath(SFPolygon poly, int pathIndex, Matrix4x4 t, ref int j, bool flipped, Vector3 properties, Vector3[] verts, Vector4[] tangents, Vector2[] uvs, int[] tris)
    {
        int     startIndex;
        Vector2 a;

        var path = poly.GetPath(pathIndex);

        if (poly.looped)
        {
            startIndex = 0;
            a          = Transform(t, path[path.Length - 1]);
        }
        else
        {
            startIndex = 1;
            a          = Transform(t, path[0]);
        }

        for (int i = startIndex; i < path.Length; i++)
        {
            var b = Transform(t, path[i]);

            var ab = (flipped ? new Vector4(b.x, b.y, a.x, a.y) : new Vector4(a.x, a.y, b.x, b.y));
            verts[j * 4 + 0] = properties; tangents[j * 4 + 0] = ab; uvs[j * 4 + 0] = new Vector2(0.0f, 0.0f);
            verts[j * 4 + 1] = properties; tangents[j * 4 + 1] = ab; uvs[j * 4 + 1] = new Vector2(1.0f, 0.0f);
            verts[j * 4 + 2] = properties; tangents[j * 4 + 2] = ab; uvs[j * 4 + 2] = new Vector2(0.0f, 1.0f);
            verts[j * 4 + 3] = properties; tangents[j * 4 + 3] = ab; uvs[j * 4 + 3] = new Vector2(1.0f, 1.0f);

            tris[j * 6 + 0] = j * 4 + 0; tris[j * 6 + 1] = j * 4 + 1; tris[j * 6 + 2] = j * 4 + 2;
            tris[j * 6 + 3] = j * 4 + 1; tris[j * 6 + 4] = j * 4 + 3; tris[j * 6 + 5] = j * 4 + 2;

            j++;
            a = b;
        }
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();
        SFPolygon poly = this.target as SFPolygon;

        EditorGUILayout.HelpBox("When editing the shadow geometry, shift+click to add new points. Command+click or control+click to remove point.", MessageType.Info);
        GUILayout.BeginHorizontal("box");

        if (GUILayout.Button(SFPolygonEditor.inEditMode ? "Stop Editing" : "Edit Shadow Geometry"))
        {
            SFPolygonEditor.inEditMode = !SFPolygonEditor.inEditMode;
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Flip Inside-Out"))
        {
            Undo.RecordObjects(this.targets, "Flip Inside-Out");
            foreach (SFPolygon t in this.targets)
            {
                t._FlipInsideOut();
                EditorUtility.SetDirty(t);
            }
        }

        if (poly.GetComponent <PolygonCollider2D> () != null)
        {
            Undo.RecordObjects(this.targets, "Copy from Collider");
            if (GUILayout.Button("Copy from Collider"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t._CopyVertsFromCollider();
                    EditorUtility.SetDirty(t);
                }
            }
        }

        GUILayout.EndHorizontal();

        PropertyField("_haveShadow");
        PropertyField("_looped");
        PropertyField("_shadowLayers");
        PropertyField("_lightPenetration", (p) => p.floatValue = Math.Max(0.0f, p.floatValue));
        PropertyField("_opacity", (p) => p.floatValue          = Mathf.Clamp01(p.floatValue));

        this.serializedObject.ApplyModifiedProperties();
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        anim = GetComponent <Animator>();
        anim.SetBool("Break", false);
        anim.SetBool("Recover", false);

        hs  = GetComponent <HealthSystem> ();
        sfp = GetComponent <SFPolygon> ();

        hs.OnObjectDead += Break;
        hs.OnObjectDead += StartRecover;
        if (turnOffSFPolygon)
        {
            hs.OnObjectDead   += TurnOffSFPolygon;
            hs.OnObjectRevive += TurnOnSFPolygon;
        }
    }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        player = Player.instance;
        door   = transform.parent;

        doorTriggerCollider = GetComponent <BoxCollider2D>();
        doorCollider        = door.GetComponent <PolygonCollider2D>();

        SFPolygonScript = door.GetComponent <SFPolygon>();

        startDoorState   = DoorState.Closed;
        currentDoorState = startDoorState;

        doorPosition = door.transform.position;

        doorAnim = door.GetComponent <Animator>();
    }
예제 #5
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();
        SFPolygon poly = this.target as SFPolygon;

        EditorGUILayout.HelpBox("When editing the shadow geometry, shift+click to add new points. Command+click or control+click to remove point.", MessageType.Info);
        GUILayout.BeginHorizontal("box");

        if (GUILayout.Button(SFPolygonEditor.inEditMode ? "Stop Editing" : "Edit Shadow Geometry"))
        {
            SFPolygonEditor.inEditMode = !SFPolygonEditor.inEditMode;
            if (Camera.main)
            {
                SFRenderer sfRen = Camera.main.GetComponent <SFRenderer>();
                if (sfRen)
                {
                    if (inEditMode)
                    {
                        preserveShadowSetting = sfRen._shadows;
                        sfRen._shadows        = false;
                    }
                    else
                    {
                        sfRen._shadows = preserveShadowSetting;
                    }
                }
            }
            EditorUtility.SetDirty(target);
        }

        if (GUILayout.Button("Flip Inside-Out"))
        {
            Undo.RecordObjects(this.targets, "Flip Inside-Out");
            foreach (SFPolygon t in this.targets)
            {
                t._FlipInsideOut();
                EditorUtility.SetDirty(t);
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal("box");

        if (poly.GetComponent <Collider2D> () != null)
        {
            Undo.RecordObjects(this.targets, "Copy from Collider");
            if (GUILayout.Button("Copy from Collider"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t._CopyVertsFromCollider();
                    EditorUtility.SetDirty(t);
                }
            }
        }
        if (poly.GetComponent <SpriteRenderer>() != null)
        {
            Undo.RecordObjects(this.targets, "Copy from Sprite");
            if (GUILayout.Button("Copy from Sprite"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t._CopyVertsFromSprite();
                    EditorUtility.SetDirty(t);
                }
            }
        }

        GUILayout.EndHorizontal();

        PropertyField("_looped");
        if (poly.GetComponent <CircleCollider2D>() != null)
        {
            PropertyField("circleVertCount");
        }
        //PropertyField("_shadowLayers");

        serializedObject.FindProperty("_shadowLayers").intValue = EditorGUILayout.LayerField("shadowLayers", serializedObject.FindProperty("_shadowLayers").intValue);
        PropertyField("_lightPenetration", (p) => p.floatValue  = Math.Max(0.0f, p.floatValue));
        PropertyField("_opacity", (p) => p.floatValue           = Mathf.Clamp01(p.floatValue));

        this.serializedObject.ApplyModifiedProperties();
    }
예제 #6
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();
        SFPolygon poly = this.target as SFPolygon;

        EditorGUILayout.HelpBox("When editing the shadow geometry, shift+click to add new points. Command+click or control+click to remove point.", MessageType.Info);

        // PropertyField("pathCount", (p) => p.intValue = Math.Max(0, p.intValue));
        PropertyField("_activePath", (p) => p.intValue = Math.Min(Math.Max(-1, p.intValue), poly.pathCount - 1));
        poly.pathCount = Math.Max(1, EditorGUILayout.DelayedIntField("Path Count", poly.pathCount));

        GUILayout.BeginHorizontal("box"); {
            if (GUILayout.Button("<"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t.activePath = Math.Max(0, t.activePath - 1);
                    EditorUtility.SetDirty(t);
                }
            }

            if (GUILayout.Button(">"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t.activePath = Math.Min(t.pathCount - 1, t.activePath + 1);
                    EditorUtility.SetDirty(t);
                }
            }

            if (GUILayout.Button("All Paths"))
            {
                foreach (SFPolygon t in this.targets)
                {
                    t.activePath = -1;
                    EditorUtility.SetDirty(t);
                }
                SFPolygonEditor.inEditMode = false;
            }

            if (poly.GetComponent <PolygonCollider2D>() || poly.GetComponent <BoxCollider2D>())
            {
                Undo.RecordObjects(this.targets, "Copy from Collider");
                if (GUILayout.Button("Copy from Collider"))
                {
                    foreach (SFPolygon t in this.targets)
                    {
                        t._CopyFromCollider();
                        EditorUtility.SetDirty(t);
                    }
                }
            }
        } GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("box"); {
            if (GUILayout.Button(SFPolygonEditor.inEditMode ? "Stop Editing" : "Edit Path"))
            {
                SFPolygonEditor.inEditMode = !SFPolygonEditor.inEditMode;
                EditorUtility.SetDirty(target);
            }

            if (GUILayout.Button("Flip Inside-Out"))
            {
                Undo.RecordObjects(this.targets, "Flip Inside-Out");
                foreach (SFPolygon t in this.targets)
                {
                    t._FlipInsideOut(t.activePath);
                    EditorUtility.SetDirty(t);
                }
            }
        } GUILayout.EndHorizontal();

        PropertyField("_looped");
        PropertyField("_shadowLayers");
        PropertyField("_lightPenetration", (p) => p.floatValue = Mathf.Max(0.0f, p.floatValue));
        PropertyField("_opacity", (p) => p.floatValue          = Mathf.Clamp01(p.floatValue));

        this.serializedObject.ApplyModifiedProperties();
    }
예제 #7
0
    private void PathGUI(SFPolygon poly, int pathIndex)
    {
        bool dirty = false;
        var  path  = poly.GetPath(pathIndex);

        bool invalidVerts = true;

        for (int i = 0; i < path.Length && invalidVerts; i++)
        {
            invalidVerts &= (path[i] == Vector2.zero);
        }

        if (invalidVerts)
        {
            Debug.Log("Invalid verts, attempting to set up from collider.");
            // copy in collider verts if possible.
            poly._CopyFromCollider();

            path  = poly.GetPath(pathIndex);
            dirty = true;
        }

        var verts = new List <Vector2>(path);

        // Copy of verts that is looped if the polygon is looped.
        var looped = new List <Vector2>(verts);

        if (poly.looped)
        {
            looped.Add(looped[0]);
        }

        Handles.matrix = poly.transform.localToWorldMatrix;

        if (!inEditMode)
        {
            Handles.color = new Color(1f, 1f, 0f, 0.4f);
        }
        else
        {
            SetupUndo("edited SFPolygon");

            var removePressed = ((Event.current.modifiers & (EventModifiers.Command | EventModifiers.Control)) != 0);
            var addPressed    = ((Event.current.modifiers & (EventModifiers.Shift)) != 0);

            if (removePressed)
            {
                if (verts.Count > 2)
                {
                    Handles.color = Color.red;

                    for (int i = 0; i < verts.Count; i++)
                    {
                        var handleSize = 0.05f * HandleUtility.GetHandleSize(verts [i]);
                        if (Handles.Button(verts [i], Quaternion.identity, handleSize, handleSize, Handles.DotHandleCap))
                        {
                            verts.RemoveAt(i);
                            dirty = true;
                            break;
                        }
                    }
                }
            }
            else if (addPressed)
            {
                int     insertIndex    = 0;
                Vector3 insertPosition = ClosestPoint(poly.transform, looped, out insertIndex);
                var     s = HandleUtility.GetHandleSize(insertPosition) * 0.05f;

                // Draw the existing vertexes
                Handles.color = Color.white;
                for (int i = 0; i < verts.Count; i++)
                {
                    Handles.DotHandleCap(0, verts [i], Quaternion.identity, s, EventType.Layout);
                }

                // Draw the insert handle
                Handles.color = Color.green;
                if (Handles.Button(insertPosition, Quaternion.identity, s, s, Handles.DotHandleCap))
                {
                    verts.Insert(insertIndex, (Vector2)insertPosition);
                    dirty = true;
                }

                HandleUtility.Repaint();
            }
            else
            {
                // Move an existing vertex
                Handles.color = Color.white;
                for (int i = 0; i < verts.Count; i++)
                {
                    Vector3 v     = verts [i];
                    Vector2 delta = DotHandle(v) - (Vector2)v;
                    if (delta != Vector2.zero)
                    {
                        verts [i] = (Vector2)v + delta;
                        dirty     = true;
                    }
                }
            }

            Handles.color = Color.white;
        }

        Handles.DrawPolyLine(looped.Select(v => (Vector3)v).ToArray());

        if (dirty)
        {
            // Unity 5.3 and later only
            Undo.RecordObject(poly, "Move Shadow Geometry");
            poly.SetPath(pathIndex, verts.ToArray());
        }
    }