Ejemplo n.º 1
0
    protected override void Awake()
    {
        try
        {
            base.Awake();

            // Application settings go here
            Application.runInBackground = true;
            Application.targetFrameRate = 60;

            // Set up required components, and just the bare minimum of MVC actors.  We don't have config data yet, so
            // anything that requires real data off the network should be registered in StartupCommand or later
            mGuiManager = new RuntimeGuiManager(mLogger);
            mLogger.AddReporter(new DebugLogReporter());
            mGameFacade = GameFacade.Instance;             // Nulls out the reference on application exit for editor integration

            // Register Required Mediators
            GameFacade.Instance.RegisterMediator(new LoggerMediator(mLogger));
            GameFacade.Instance.RegisterMediator(new InputManagerMediator());
            GameFacade.Instance.RegisterMediator(new SchedulerMediator(this.Scheduler));
            GameFacade.Instance.RegisterMediator((IMediator)mGuiManager);

            RuntimeConsole runtimeConsole = new RuntimeConsole(mGuiManager);
            runtimeConsole.AddCommand("showTasks", ((Scheduler)this.Scheduler).ShowTasks);
            ((Scheduler)this.Scheduler).Logger = mLogger;
            GameFacade.Instance.RegisterMediator(runtimeConsole);
            mLogger.AddReporter(runtimeConsole);

            mLogger.Log("SceneInit.Awake", LogLevel.Info);

            ConnectionProxy connectionProxy = new ConnectionProxy();
            GameFacade.Instance.RegisterProxy(connectionProxy);

            // Get configuration data before doing anything else.  This sends STARTUP_COMMAND when done getting the config data
            ConfigManagerClient configManager = new ConfigManagerClient();
            GameFacade.Instance.RegisterProxy(configManager);
            configManager.InitAndStartup();
        }
        catch (System.Exception ex)
        {
            // Catch all here is to avoid browser crashes on exit if something becomes unstable.
            mLogger.Log(ex.ToString(), LogLevel.Error);
        }
        finally
        {
            mLogger.Flush();
        }
    }
Ejemplo n.º 2
0
        private IEnumerator <IYieldInstruction> WalkingTask(Pair <Vector3> target, Hangout.Shared.Action onTargetReachedCallback)
        {
            Vector3 headingSmooth = this.UnityGameObject.transform.forward;

            do
            {
                this.DisplayObject.animation[mActiveWalkCycle.name].speed = mWalkSpeed * mActiveWalkCycleSpeed;

                yield return(new YieldUntilNextFrame());

                Vector3 position           = this.UnityGameObject.transform.position;
                Vector3 positionDifference = target.First - position;
                float   distanceToTarget   = positionDifference.magnitude;
                if (distanceToTarget < 0.00001f)
                {
                    // Avoid divide by zero and floating point rounding weirdness
                    break;
                }
                Vector3 directionToTarget = positionDifference / distanceToTarget;
                Vector3 heading           = directionToTarget;

                ConfigManagerClient configManager = GameFacade.Instance.RetrieveProxy <ConfigManagerClient>();

                bool enableCollisionAvoidance = configManager.GetBool("enableCollisionAvoidance", true);

                if (enableCollisionAvoidance)
                {
                    Vector3 avoidCollisionsVect = Vector3.zero;
                    int     collisionLayer      = mStateMachine.CurrentFashionState.CollisionCheckLayer;
                    foreach (Collider collider in Physics.OverlapSphere(position, COLLISION_CHECK_RADIUS, collisionLayer))
                    {
                        if (collider.gameObject == UnityGameObject)
                        {
                            continue;
                        }

                        Vector3 colliderToModel = collider.gameObject.transform.position - position;

                        float   weight = -1.0f / Mathf.Max(colliderToModel.sqrMagnitude, 0.01f);                      // inverse square weight
                        Vector3 avoidCollisionInfluence = colliderToModel.normalized * weight;
                        if (Vector3.Dot(avoidCollisionInfluence, positionDifference) > 0.3f)                          // make sure we only influence towards the end goal
                        {
                            avoidCollisionsVect += avoidCollisionInfluence;
                        }
                    }

                    DebugUtility.DrawCicrleXZ(position, COLLISION_CHECK_RADIUS, Color.yellow);

                    if (avoidCollisionsVect.magnitude > 0.0f)
                    {
                        Debug.DrawLine(position, position + avoidCollisionsVect, Color.yellow);

                        heading += avoidCollisionsVect * Mathf.Clamp01(distanceToTarget * DISTANCE_TO_TARGET_CHECK);
                        heading.Normalize();

                        headingSmooth += heading * Time.deltaTime;
                        headingSmooth.Normalize();

                        Debug.DrawLine(position, position + headingSmooth, Color.green);
                        heading = headingSmooth;
                    }
                    else
                    {
                        headingSmooth = heading;
                    }
                }
                else
                {
                    headingSmooth = heading;
                }

                this.UnityGameObject.transform.position += headingSmooth * mWalkSpeed * Time.deltaTime;

                // Walk towards the target
                this.UnityGameObject.transform.forward = headingSmooth;
            }while (DistanceTo(target.First) > (mWalkSpeed * Time.deltaTime * 1.1f));

            this.UnityGameObject.transform.position = target.First;
            this.UnityGameObject.transform.forward  = target.Second;

            if (onTargetReachedCallback != null)
            {
                onTargetReachedCallback();
            }
        }