Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     module = GetComponent <Module>();
     if (module.meshGo)
     {
         var filter = module.meshGo.GetComponent <MeshFilter>();
         if (filter)
         {
             var bounds = filter.sharedMesh.bounds;
             var center = bounds.center;
             var size   = module.size;
             boundingPoints = new BoundingPoints(center, new Vector3(size.x, size.y, size.z));
             // Debug.LogFormat("x{0} y{1} z{2}",size.x, size.y, size.z);
         }
     }
     GroundPlan.instance.initCount++;
 }
Ejemplo n.º 2
0
        public Player() : base(name)
        {
            Position = new Vector2(400, 400);

            Animations.Add("left", AnimationManager.Get(name, "left", 8));
            Animations.Add("right", AnimationManager.Get(name, "right", 8));
            Animations.Add("waitright", AnimationManager.Get(name, "waitright", 1));
            Animations.Add("waitleft", AnimationManager.Get(name, "waitleft", 1));
            Animations.Add("jumpleft", AnimationManager.Get(name, "jumpleft", 4, false));
            Animations.Add("jumpright", AnimationManager.Get(name, "jumpright", 4, false));

            Direction     = Direction.Right;
            CurrentAction = Actions.StandStill;

            SetWaitAnimation();
            Texture = CurrentAnimation.Frame;

            BoundingPoints.Add(new BoundingPoint()
            {
                X            = 12 * 2,
                Y            = 35 * 2 + 1,
                Intersection = new ActorEventHandler(target => target.ApplyGravity = false)
            });

            BoundingPoints.Add(new BoundingPoint()
            {
                X            = 23 * 2,
                Y            = 35 * 2 + 1,
                Intersection = new ActorEventHandler(target => target.ApplyGravity = false)
            });

            BoundingPoints.Add(new BoundingPoint()
            {
                X            = 24 * 2 + 1,
                Y            = 12 * 2,
                Intersection = new ActorEventHandler(target => target.CanMoveRight = false)
            });

            BoundingPoints.Add(new BoundingPoint()
            {
                X            = 7 * 2 - 1,
                Y            = 12 * 2,
                Intersection = new ActorEventHandler(target => target.CanMoveLeft = false)
            });
        }
Ejemplo n.º 3
0
    // Use this for initialization
    IEnumerator Start()
    {
        this.gameObject.name = id;

        showPoints             = true;
        showEncapsulatedPoints = true;
        showEdges = true;

        // Set the size of the volume to the closest measurement contained in the red series
        float length = LeModular.GetClosest(bc.length * 100) / 100;
        float width  = LeModular.GetClosest(bc.width * 100) / 100;
        float height = LeModular.GetClosest(bc.height * 100) / 100;

        bc.Set(length, width, height);

        // Find all the bounding points
        skinnedMesh = GetComponentInChildren <SkinnedMeshRenderer>();
        skinnedMesh.updateWhenOffscreen = true;
        bounds         = skinnedMesh.bounds;
        center         = bounds.center;
        boundingPoints = new BoundingPoints(center, new Vector3(width, height, length));
        Debug.LogFormat("{0}{1}{2}", width, height, length);
        // Add box collider and rigidbody to generate collisions
        boxCollider           = bc.gameObject.AddComponent <BoxCollider>();
        boxCollider.enabled   = true;
        boxCollider.isTrigger = true;
        boxCollider.center    = center;
        boxCollider.size      = new Vector3(bc.width, bc.height, bc.length);
        rb             = bc.gameObject.AddComponent <Rigidbody>();
        rb.isKinematic = true;
        yield return(new WaitUntil(() => triggerStay));

        CubeGenerator.Instance.ready++;
        // Debug.Log(string.Format("Modulor Agent {0} Agent List Count{1}",id, modulorAgents.Count));
        // Iterate through our bounding points to see if any of them are within the bounds of another agent
        CubeGenerator.Instance.agentDict[this].AddRange(boundingPoints.all);

        foreach (Vector3 point in boundingPoints.all)
        {
            foreach (ModulorAgent agent in modulorAgents)
            {
                if (agent.bounds.Contains(point))
                {
                    if (encapsulatedPoints.ContainsKey(agent))
                    {
                        encapsulatedPoints[agent].Add(point);
                    }
                    else
                    {
                        List <Vector3> points = new List <Vector3>();
                        points.Add(point);
                        encapsulatedPoints.Add(agent, points);
                    }
                }
                else
                {
                    //
                }
            }
        }


        foreach (var entry in this.encapsulatedPoints)
        {
            foreach (var edge in boundingPoints.edges)
            {
                if (!entry.Value.Contains(edge.v1.position) & !entry.Value.Contains(edge.v2.position))
                {
                    continue;
                }
                var dir = edge.v2.position - edge.v1.position;
                dir.Normalize();
                Ray   ray      = new Ray(edge.v1.position, dir);
                float distance = 0;

                if (entry.Key.bounds.IntersectRay(ray, out distance))
                {
                    Vector3 point = ray.origin + ray.direction * distance;
                    intersectionPoints.Add(point);
                    intersectionEdges.Add(new Edge(ray.origin, point));
                }
            }
        }

        foreach (Vector3 vector in boundingPoints.all)
        {
            Vector3 worldPoint = this.transform.TransformPoint(vector);
            if (!CubeGenerator.Instance.points.Contains(worldPoint))
            {
                CubeGenerator.Instance.points.Add(worldPoint);
            }
        }

        foreach (Vector3 vector in intersectionPoints)
        {
            Vector3 worldPoint = this.transform.TransformPoint(vector);
            if (!CubeGenerator.Instance.points.Contains(worldPoint))
            {
                CubeGenerator.Instance.points.Add(worldPoint);
            }
        }

        // bc.GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;

        // TODO: refactor what's below
        var refactor = false;

        if (refactor)
        {
            // Instantiate piloti if the volume is off the ground
            if (offGround)
            {
                var piloti = Resources.Load <GameObject>("piloti");
                var pos    = center;
                pos.y -= bc.height / 2;
                piloti = Instantiate(piloti, pos, Quaternion.identity, this.transform);
                var pilotiScript = piloti.GetComponent <Pilotis>();
                // get the shortest side
                pilotiScript.length = bc.width;
                pilotiScript.width  = bc.length;
                var a = pilotiScript.length > pilotiScript.width ? pilotiScript.width : pilotiScript.length;            // get the shortet side
                a *= 0.1f;
                a  = Mathf.Clamp(a, 0.1f, 0.75f);
                pilotiScript.pilotiWidth = a;
                pilotiScript.width      -= a;
                pilotiScript.length     -= a;
                var ground = bc.a.position;
                ground.y = 0;
                height   = Vector3.Distance(bc.a.position, ground);
            }

            List <float> floors  = LeModular.Divisions(bc.height);
            var          floorBC = BonedCube.Make();
            floorBC.transform.SetParent(this.transform);
            floorBC.a.transform.position = this.bc.a.transform.position;
            floorBC.Set(bc.length, bc.width, 0.1f);
            var _floors = BuildFloors(floors);
            if (_floors != null)
            {
                foreach (var floor in _floors)
                {
                    floorBC = BonedCube.Make();
                    floorBC.transform.SetParent(this.transform);
                    floorBC.a.transform.position = this.bc.a.transform.position + new Vector3(0, floor, 0);
                    floorBC.Set(bc.length, bc.width, 0.1f);
                }
            }
        }
    }