Exemplo n.º 1
0
            /// <summary>
            /// Call from your Start method
            /// </summary>
            protected void Start()
            {
                if (null != iface)
                {
                    return;
                }
                AdvertisePath();
                GameObject go       = this.gameObject;
                PathHolder holder   = null;
                string     usedPath = path;

                while (null != go && 0 == usedPath.Length)
                {
                    holder = go.GetComponent <PathHolder>();
                    if (null != holder)
                    {
                        usedPath = holder.path;
                        //print("[OSVR] " + name + ": Found path " + usedPath + " in ancestor " + go.name);
                    }
                    go = GetParent.Get(go);
                }

                if (0 == usedPath.Length)
                {
                    Debug.LogError("[OSVR] Missing path for " + name + " - no path found in this object's InterfaceGameObject or any ancestor!");
                    return;
                }

                iface      = ScriptableObject.CreateInstance <InterfaceCallbacks>();
                iface.path = usedPath;
                iface.Start();
            }
Exemplo n.º 2
0
    //completes the task. If the task has already been completed, it does nothing.
    public void finishTask(List <int> nodePath, List <Vector3> path, float pathLength)
    {
        //if we haven't already finished this task
        if (!finishedTask)
        {
            //make a new pathHolder
            pathHolder = new PathHolder();
            //give it all these characteristicts
            pathHolder.nodePath   = nodePath;
            pathHolder.path       = path;
            pathHolder.pathLength = pathLength;
            //make sure you can't finish the task again.
            finishedTask = true;

            if (costIncrease == 0)
            {
                return;
            }

            if (nodePath != null)
            {
                foreach (int n in nodePath)
                {
                    cost[n] += costIncrease;
                }
            }
        }
    }
Exemplo n.º 3
0
            /// <summary>
            /// Call from your Awake method to advertise the presence or absence of a path specification on this game object.
            /// </summary>
            protected void AdvertisePath()
            {
                if (null != iface)
                {
                    /// Already started.
                    return;
                }

                PathHolder holder = GetComponent <PathHolder>();

                if (path.Length > 0)
                {
                    /// If we have a path, be sure we advertise it.
                    if (null == holder)
                    {
                        holder = gameObject.AddComponent <PathHolder>();
                    }
                    holder.path = path;
                }
                else
                {
                    /// Don't advertise a path that is empty
                    if (null != holder)
                    {
                        Object.Destroy(holder);
                    }
                }
            }
Exemplo n.º 4
0
        protected virtual void Stop()
        {
            PathHolder holder = GetComponent <PathHolder>();

            if (null != holder)
            {
                Object.Destroy(holder);
            }
        }
Exemplo n.º 5
0
            protected void Stop()
            {
                if (null != iface)
                {
                    Object.Destroy(iface);
                    iface = null;
                }
                PathHolder holder = GetComponent <PathHolder>();

                if (null != holder)
                {
                    Object.Destroy(holder);
                }
            }
Exemplo n.º 6
0
    Path GetClosestPath(PathHolder holder)
    {
        float bestDistance = Mathf.Infinity;
        Path  bestPath     = null;

        foreach (var path in holder.paths)
        {
            float distance = Vector3.Distance(transform.position, path.transform.position);

            if (distance < bestDistance)
            {
                bestDistance = distance;
                bestPath     = path;
            }
        }

        return(bestPath);
    }
Exemplo n.º 7
0
    //initialization
    public PathTask(Vector3 start, Vector3 finish, PathHolder oldPathHolder, int costIncrease)
    {
        this.start         = start;
        this.finish        = finish;
        pathHolder         = null;
        this.oldPathHolder = oldPathHolder;
        finishedTask       = false;

        this.costIncrease = costIncrease;

        //decrease costs for old path
        if (oldPathHolder != null && oldPathHolder.nodePath != null)
        {
            foreach (int n in oldPathHolder.nodePath)
            {
                cost[n] -= costIncrease;
            }
        }
    }
Exemplo n.º 8
0
    //updates the pathTask if it hasn't been completed, makes a new pathTask if it has.
    public void updatePathTask(Vector3 start, Vector3 finish)
    {
        if (currentTask == null || currentTask.finishedTask)
        {
            //get the old pathHolder, and set the path if the task has been finished.
            PathHolder oldPathHolder = null;
            if (currentTask != null && currentTask.pathHolder != null)
            {
                oldPathHolder = currentTask.pathHolder;
                path          = currentTask.pathHolder.path;
            }

            //create a new task, set it to the current task
            currentTask = new PathTask(start, finish, oldPathHolder, costIncrease);
            //add the task
            map.AddTask(currentTask);
        }
        else
        {
            currentTask.start  = start;
            currentTask.finish = finish;
        }
    }
Exemplo n.º 9
0
        /// <summary>
        /// Call from your Start method
        /// </summary>
        protected virtual void Start()
        {
            AdvertisePath();
            GameObject go     = this.gameObject;
            PathHolder holder = null;

            while (null != go && System.String.IsNullOrEmpty(usedPath))
            {
                usedPath = path;
                holder   = go.GetComponent <PathHolder>();
                if (null != holder)
                {
                    usedPath = holder.path;
                    //Debug.Log("[OSVR-Unity] " + name + ": Found path " + usedPath + " in ancestor " + go.name);
                }
                go = GetParent.Get(go);
            }

            if (0 == usedPath.Length)
            {
                Debug.LogError("[OSVR-Unity] Missing path for " + name + " - no path found in this object's InterfaceGameObject or any ancestor!");
                return;
            }
        }