Ejemplo n.º 1
0
            public TValue GetOrCreate(Func <TKey, TValue> valueFactory)
            {
                TValue local;

                if (!this.TryGet(out local))
                {
                    local = valueFactory(this.key);
                    if (this.weakRef == null)
                    {
                        this.weakRef = new WeakReferenceT <TValue>(local);
                        return(local);
                    }
                    this.weakRef.Target = local;
                }
                return(local);
            }
Ejemplo n.º 2
0
	public void SetBehaviorContext(WeakReferenceT<BehaviorContext> newContext)
	{
		if (!_currentContext.IsAlive)
		{
			_currentContext = newContext;
			OnBehaviorTreeChanged();
		}

		if (newContext.Target == _currentContext.Target)
			return;


		_currentContext = newContext;

		_contextDrawer.behaviorContext = newContext;

		OnBehaviorTreeChanged();
	}
Ejemplo n.º 3
0
		public INode AddTree(string behaviorTreeKey, INode behaviorTree)
		{
			if (behaviorTrees.ContainsKey(behaviorTreeKey))
			{
				if (behaviorTrees[behaviorTreeKey].IsAlive == false)
				{
					behaviorTrees[behaviorTreeKey] = new WeakReferenceT<INode>(behaviorTree);
					behaviorTree.SetBehaviorState(this);
				}
				else
				{
					Debug.LogError("Tried add tree that already exists with key: " + behaviorTreeKey);
				}
			}
			else
			{
				behaviorTrees.Add(behaviorTreeKey, new WeakReferenceT<INode>(behaviorTree));
			}

			return behaviorTree;
		}
Ejemplo n.º 4
0
        public void L2CapListen()
        {
            L2CapListener lsnr = null;

            try {
                lsnr = L2CapListen_();
                var cli = lsnr.AcceptClient();
                console.WriteLine("Accepted! :-)");
                //
                _peer     = cli.GetStream();
                _cliL2Cap = new WeakReferenceT <L2CapClient>(cli);
                console.WriteLine("Got connection from: {0}", cli.RemoteEndPoint);
                //PrintLocalEndpointIfAvailable(cli);
                PrintMtuEtc(cli);
                console.Pause("Un-pause to continue; and close listener");
            } finally {
                if (lsnr != null)
                {
                    lsnr.Stop();
                }
            }
        }
Ejemplo n.º 5
0
        public void L2CapConnect()
        {
            BluetoothAddress addr      = console.ReadBluetoothAddress("Server's BluetoothAddress");
            Guid             svcClass  = SvcClassForL2CapTests;
            Guid?            inputGuid = console.ReadOptionalBluetoothUuid("UUID", svcClass);

            if (inputGuid.HasValue)
            {
                svcClass = inputGuid.Value;
            }
            int?port = console.ReadOptionalInteger("Port number (L2CAP PSM)");

            // to-do: auth/encrypt/setpin
            bool@async = true; //console.ReadYesNo("Async Connect?", false);
            bool asyncCallback = true;
            //if @async) {
            //    asyncCallback = console.ReadYesNo("Async Callback?", true);
            //}
            //
            BluetoothEndPoint rep;

            if (port == null)
            {
                rep = new BluetoothEndPoint(addr, svcClass);
            }
            else
            {
                rep = new BluetoothEndPoint(addr, svcClass, port.Value);
            }
            console.WriteLine("Connecting to: {0}:{1}:{2} ...", rep.Address, rep.Service, rep.Port);
            //
            var cli = new L2CapClient();

            if (@async)
            {
                AsyncCallback cb = null;
                if (asyncCallback)
                {
                    cb = MiscCallback;
                }
                IAsyncResult ar = cli.BeginConnect(rep,
                                                   cb, "BeginConnect");
                console.WriteLine("(BeginConnect returned)");
#if NETCF // ReadYesNo will block the screen. :-(
                console.Pause("Paused after BeginConnect");
#endif
                bool closeNow = console.ReadYesNo("Respond when we should proceed to EndConnect.  Enter Y to call Close first.", false);
                if (closeNow)
                {
                    cli.Close();
                }
                cli.EndConnect(ar);
            }
            else
            {
                cli.Connect(rep);
            }
            console.WriteLine("Connected to : {0}", cli.RemoteEndPoint);
            //PrintLocalEndpointIfAvailable(cli);
            PrintMtuEtc(cli);
            //----
            _peer     = cli.GetStream();
            _cliL2Cap = new WeakReferenceT <L2CapClient>(cli);
        }
Ejemplo n.º 6
0
		public override void DrawWindow(int id)
		{
			var behaviorState = BehaviorState.GetBehaviorStateInScene();
			if (behaviorState == null)
			{
				GUILayout.Label("No state, no context.");
				return;
			}
			var behaviorContexts = behaviorState.behaviorContexts;


			if (_currentSelected.IsAlive)
			{
				GUI.contentColor = Color.black;
				GUILayout.Label(_currentSelected.Target.ToString());


			}
			else
			{
				GUI.contentColor = Color.red;
				GUILayout.Label("No context selected");
			}

			GUILayout.Space(10f);

			_filterText = GUILayout.TextField(_filterText);

			bool filterText = _filterText != "";


			_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

			foreach (WeakReferenceT<BehaviorContext> contextRef in behaviorContexts)
			{
				if (contextRef.IsAlive == false)
					break;

				var name = contextRef.Target.ToString();

				if (!filterText || name.Contains(_filterText))
				{
					if (contextRef.IsAlive)
					{
						if (GUILayout.Button(name))
						{
							_currentSelected = contextRef;
							this._parent.SetBehaviorContext(contextRef);
						}
					}
					else
					{
						GUI.enabled = false;
						if (GUILayout.Button(name))
						{

						}
						GUI.enabled = true;

					}
				}


			}

			EditorGUILayout.EndScrollView();
			if (id != -1)
				GUI.DragWindow();

		}
Ejemplo n.º 7
0
		public BehaviorContextSelectorWindow(BehaviorTreeWindow parent) : base(parent)
		{
			WindowTitle = "Select Context";

			_windowRect = new Rect(200f, 100f, 200f, 500f);

			_currentSelected = new WeakReferenceT<BehaviorContext>(null);

		}
Ejemplo n.º 8
0
	public BehaviorContextDrawer()
	{
		_windowRect = new Rect(200f, 200f, 400f, 600f);

		behaviorContext = new WeakReferenceT<BehaviorContext>(null);
	}
Ejemplo n.º 9
0
	private void DrawToolsWindow(int id)
	{
		GUILayout.Label("Base Settings", EditorStyles.boldLabel);

		if (GUILayout.Button("Reset Tree"))
		{
			_rootNode = null;
			
			_currentNode = new KeyValuePair<string, WeakReferenceT<INode>>("", new WeakReferenceT<INode>(null));
			_currentContext = new WeakReferenceT<BehaviorContext>(null);

			if (_contextDrawer != null)
			{
				_contextDrawer.behaviorContext = _currentContext;
			}
		}

		if (_currentContext.Target != null)
		{
			if (GUILayout.Button("Reset uses"))
			{
				var state = _currentContext.Target.state;

				foreach (var baseNodeState in state.Values)
				{
					baseNodeState.timesFailure = 0;
					baseNodeState.timesRunning = 0;
					baseNodeState.timesSuccess = 0;
				}
			}
		}

		GUI.DragWindow();
	}
Ejemplo n.º 10
0
	public BehaviorTreeWindow()
	{
		_currentNode = new KeyValuePair<string, WeakReferenceT<INode>>("", new WeakReferenceT<INode>(null));
		_currentContext = new WeakReferenceT<BehaviorContext>(null);

		var title = new GUIContent("Behavior Tree");
		titleContent = title;
		_scrollViewRect = new Rect(0,0,12000f, 5000f);

		_scrollPosition = Vector2.zero;

		_zoomLevel = Vector2.one;

		_toolsWindowRect = new Rect(0, 0, 130f, 240f);

		_contextDrawer = new BehaviorContextDrawer();

		_treeSelectorWindow = new BehaviorTreeSelectorWindow(this);
		_contextSelectorWindow = new BehaviorContextSelectorWindow(this);
	}
Ejemplo n.º 11
0
 private LazyWeakResult(T value)
 {
     this.weakValue = new WeakReferenceT <T>(value);
 }