/** Schedules the 'update' selector for a given target with a given priority. * The 'update' selector will be called every frame. * The lower the priority, the earlier it is called. * @since v0.99.3 */ public void scheduleUpdate(System.Object target, int priority, bool paused) { tHashUpdateEntry hashElement = hashForUpdates.HASH_FIND_INT(target.GetHashCode()); if (hashElement != null) { if (CCDebug.COCOS2D_DEBUG >= 1) { NSUtils.Assert(hashElement.entry.obj.markedForDeletion, "CCScheduler: You can't re-schedule an 'update' selector'. Unschedule it first"); } // TODO : check if priority has changed! hashElement.entry.obj.markedForDeletion = false; return; } // most of the updates are going to be 0, that's way there // is an special list for updates with priority 0 if (priority == 0) { appendIn(updates0, target, paused); } else if (priority < 0) { priorityIn(updatesNeg, target, priority, paused); } else // priority > 0 { priorityIn(updatesPos, target, priority, paused); } }
/** initializes the action */ public void initWithAction(CCActionInterval action) { NSUtils.Assert(action != null, "Ease: arguments must be non-nil"); base.initWithDuration(action.duration); _inner = action; }
/** initializes the action with an Animation and will restore the original frame when the animation is over */ public void initWithAnimation(CCAnimation anim) { NSUtils.Assert(anim != null, "Animate: argument Animation must be non-nil"); float singleDuration = anim.duration; base.initWithDuration(singleDuration * anim.loops); _nextFrame = 0; this.animation = anim; _origFrame = null; _executedLoops = 0; _splitTimes = new List <float> (anim.frames.Count); float accumUnitsOfTime = 0; float newUnitOfTimeValue = singleDuration / anim.totalDelayUnits; var enumerator = anim.frames.GetEnumerator(); while (enumerator.MoveNext()) { var frame = enumerator.Current; float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; accumUnitsOfTime += frame.delayUnits; _splitTimes.Add(value); } }
public void DL_DELETE(utNode <T> del) { NSUtils.Assert((del).prev != null, "del.prev should not be null."); if ((del).prev == (del)) { (_head) = null; } else if ((del) == (_head)) { (del).next.prev = (del).prev; (_head) = (del).next; } else { (del).prev.next = (del).next; if ((del).next != null) { (del).next.prev = (del).prev; } else { (_head).prev = (del).prev; } } }
/** Executes an action, and returns the action that is executed. * The node becomes the action's target. * @warning Starting from v0.8 actions don't retain their target anymore. * @since v0.7.1 * @return An Action pointer */ public CCAction runAction(CCAction action) { NSUtils.Assert(action != null, "Argument must be non-nil"); _actionManager.addAction(action, this, !_isRunning); return(action); }
public void generateGearsInEditMode(string category, Type[] componentTypes, int num) { NSUtils.Assert(!Application.isPlaying, "CCFactory:generateGearsInEditMode works in edit mode only!"); if (componentTypes == null) { componentTypes = new Type[0]; } Storage storage = getStorage(category, true); storage.componentTypeNames = new string[componentTypes.Length]; for (int i = 0; i < componentTypes.Length; i++) { storage.componentTypeNames[i] = componentTypes[i].AssemblyQualifiedName; } for (int i = 0; i < num; i++) { CCFactoryGear gear = buildGear(componentTypes); gear.gameObject.name = string.Format("{0}-{1}", category, i); gear.gameObject.transform.parent = transform; gear.gameObject.hideFlags = HideFlags.HideInHierarchy; gear.gameObject.SetActive(false); storage.gears.Add(gear); } }
public virtual CCActionFiniteTime reverse() { CCActionFiniteTime act = (CCActionFiniteTime)reverseImpl(); NSUtils.Assert(act != null, "{0}:reverseImpl not implemented", GetType().Name); return(act); }
public new virtual CCActionFiniteTime copy() { CCActionFiniteTime act = (CCActionFiniteTime)copyImpl(); NSUtils.Assert(act != null, "{0}:copyImpl not implemented", GetType().Name); return(act); }
public void initWithAction(CCActionFiniteTime action) { NSUtils.Assert(action != null, "CCReverseTime: action should not be nil"); NSUtils.Assert(action != _other, "CCReverseTime: re-init doesn't support using the same arguments"); base.initWithDuration(action.duration); _other = action; }
/** * repeat will execute the action repeat + 1 times, for a continues action use kCCRepeatForever * delay is the amount of time the action will wait before execution */ public void schedule(TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0) { NSUtils.Assert(selector != null, "Argument must be non-nil"); NSUtils.Assert(FloatUtils.EB(interval, 0), "Arguemnt must be positive"); _scheduler.schedule(selector, this, interval, repeat, !_isRunning, delay); }
public override void ccTouchCancelled(UITouch touch) { NSUtils.Assert(_state == kCCMenuState.TrackingTouch, "[Menu ccTouchCancelled] -- invalid state"); _selectedItem.unselected(); _state = kCCMenuState.Waiting; }
public void runWithScene(CCScene scene) { NSUtils.Assert(scene != null, "Argument must be non-nil"); NSUtils.Assert(_runningScene == null, "This command can only be used to start the CCDirector. There is already a scene present."); pushScene(scene); startAnimation(); }
public virtual void reorderChild(CCNode child, int z) { NSUtils.Assert(child != null, "Child must be non-nil"); _isReorderChildDirty = true; child.orderOfArrival = globalOrderOfArrival++; child._setZOrder(z); }
public virtual void removeChildAndCleanup(CCNode child, bool cleanup) { if (child == null) { return; } NSUtils.Assert(_children.Contains(child), "This node does not contain the specified child."); detachChild(child, cleanup); }
public override void addChild(CCNode child, int z, string tag) { NSUtils.Assert(child != null, "Argument must be non-nil"); //CCNode already sets _isReorderChildDirty so this needs to be after batchNode check base.addChild(child, z, tag); // _hasChildren = true; }
static CCTMXLayer ParseLayer(XmlNode nodeData, int cols, int rows, Dictionary <int, string> gidToFiles, Dictionary <int, Dictionary <string, string> > gidToTileProperties) { XmlNode data = nodeData.SelectSingleNode("data"); string name = nodeData.Attributes["name"].InnerText; string encoding = data.Attributes["encoding"].InnerText; NSUtils.Assert(encoding == "csv", "cocos2d:CCTMXMapParser: Unsupported encoding {0} found. Only csv is supported now.", encoding); string csvData = data.InnerText; CCTMXTiledLayer layer = new CCTMXTiledLayer(); layer.name = name; layer.visiable = nodeData.Attributes["visible"] != null && nodeData.Attributes["visible"].InnerText == "0"; layer.tiles = new CCTMXTile[rows][]; for (int row = 0; row < rows; row++) { layer.tiles[row] = new CCTMXTile[cols]; } string[] layerData = csvData.Split(','); int totalTiles = cols * rows; for (int i = 0; i < totalTiles; i++) { int col = i % cols; int row = Mathf.FloorToInt(i / cols); int tileId = int.Parse(layerData[i].ToString().Trim()); if (tileId > 0) { CCTMXTile tile = new CCTMXTile(); tile.gid = tileId; tile.col = col; tile.row = row; try{ tile.file = gidToFiles[tile.gid]; }catch { throw new UnityEngine.UnityException(string.Format("cocos2d: CCTMXMapParser: gid [{0}] not found", tile.gid)); } Dictionary <string, string> tileProperties = null; if (!gidToTileProperties.TryGetValue(tile.gid, out tileProperties)) { tileProperties = null; } tile.sharedProperties = tileProperties; layer.tiles[row][col] = tile; } } XmlNode propertiesNode = nodeData.SelectSingleNode("properties"); if (propertiesNode != null) { layer.properties = new Dictionary <string, string>(); ParseProperties(propertiesNode, layer.properties); } return(layer); }
public void gotoAndStop(string label) { int frame; if (!_define.label_indexs.TryGetValue(label, out frame)) { NSUtils.Assert(false, "BBFlashMovie:gotoAndStop: Label {0} not found.", label); } gotoAndStop(frame); }
/** Initializes a timer with a target, a selector, an interval in seconds, repeat in number of times to repeat, delay in seconds */ public CCTimerTargetSelector(System.Object t, TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0) { if (CCDebug.COCOS2D_DEBUG >= 1) { NSUtils.Assert(selector != null, "Method not found for selector - does it have the following form? void name(float dt)"); } _target = t; _selector = selector; setupTimer(interval, repeat, delay); }
// // Designated initializer // protected void initWithString(string value, CCMenuItemDelegate block) { NSUtils.Assert(value.Length > 0, "Value length must be greater than 0"); _fontName = _globalFontName; _fontSize = _globalFontSize; CCLabelTTF label = new CCLabelTTF(value, _fontName, _fontSize); initWithLabel(label, block); }
public override void reorderChild(CCNode child, int z) { NSUtils.Assert(child != null, "Child must be non-nil"); NSUtils.Assert(_children.Contains(child), "Child doesn't belong to Sprite"); if (z == child.zOrder) { return; } base.reorderChild(child, z); }
public static CCActionFiniteTime ActionWithArray(CCActionFiniteTime[] actions) { NSUtils.Assert(actions != null && actions.Length > 0, "CCActionSequence: actions should not be null."); CCActionFiniteTime prev = actions [0]; for (int i = 1; i < actions.Length; i++) { prev = ActionWithOneTwo(prev, actions [i]); } return(prev); }
/** Adds an animation from a plist file. * Make sure that the frames were previously loaded in the CCSpriteFrameCache. * @since v1.1 */ public void addAnimationsWithFile(string plist) { NSUtils.Assert(plist != null, "Invalid texture file name"); NSDictionary dict = NSDictionary.DictionaryWithContentsOfFileFromResources(plist); NSUtils.Assert(dict != null, "CCAnimationCache: File could not be found: {0}", plist); addAnimationsWithDictionary(dict); }
static string LoadText(string file) { NSUtils.Assert(file.EndsWith(".txt"), "Text file in Resources folder must be '*.txt' format!"); string ext = Path.GetExtension(file); file = file.Replace(ext, ""); TextAsset asset = Resources.Load <TextAsset> (file); NSUtils.Assert(asset != null, "cocos2d: CCTmxParser:File not found :{0}.", file); return(asset.text); }
public void unscheduleBlockForKey(string key, System.Object target) { // explicity handle nil arguments when removing an object if (target == null && key == null) { return; } NSUtils.Assert(target != null, "Target MUST not be nil"); NSUtils.Assert(key != null, "key MUST not be NULL"); tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode()); if (element != null) { for (int i = 0; i < element.timers.Count; i++) { CCTimer timer = element.timers[i]; if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key) { if (timer == element.currentTimer && !element.currentTimerSalvaged) { element.currentTimerSalvaged = true; } element.timers.RemoveAt(i); // update timerIndex in case we are in tick:, looping over the actions if (element.timerIndex >= i) { element.timerIndex--; } if (element.timers.Count == 0) { if (currentTarget == element) { currentTargetSalvaged = true; } else { removeHashElement(element); } } return; } } } // Not Found // NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString); }
protected void initWithAction(CCActionFiniteTime one, CCActionFiniteTime two) { NSUtils.Assert(one != null && two != null, "Sequence: arguments must be non-nil"); NSUtils.Assert(one != _actions[0] && one != _actions[1], "Sequence: re-init using the same parameters is not supported"); NSUtils.Assert(two != _actions[1] && two != _actions[0], "Sequence: re-init using the same parameters is not supported"); float d = one.duration + two.duration; base.initWithDuration(d); _actions [0] = one; _actions [1] = two; }
public override void ccTouchMoved(UITouch touch) { NSUtils.Assert(_state == kCCMenuState.TrackingTouch, "[Menu ccTouchMoved] -- invalid state"); CCMenuItem currentItem = itemForTouch(touch); if (currentItem != _selectedItem) { _selectedItem.unselected(); _selectedItem = currentItem; _selectedItem.selected(); } }
public void pushScene(CCScene scene) { NSUtils.Assert(scene != null, "Argument must be non-nil"); _sendCleanupToScene = false; if (_runningScene != null) { _runningScene.gameObject.SetActive(false); } _scenesStack.Push(scene); _nextScene = scene; // _nextScene is a weak ref }
// load dictionary from lists public void OnAfterDeserialize() { this.Clear(); NSUtils.Assert(keys.Count == values.Count, "there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable.", keys.Count, values.Count ); for (int i = 0; i < keys.Count; i++) { this.Add(keys[i], values[i]); } }
public CCSpriteFrame(string file) { _textureFilename = file; string ext = Path.GetExtension(file); if (ext != null && ext.Length > 0) { file = file.Replace(ext, ""); } Sprite s = Resources.Load <Sprite> (file); NSUtils.Assert(s != null, "Sprite {0} not found!", file); init(s); }
/** Changes the priority of a previously added delegate. The lower the number, * the higher the priority */ public void setPriority(int priority, System.Object aDelegate) { NSUtils.Assert(aDelegate != null, "Got nil touch delegate!"); CCTouchHandler handler = null; handler = findHandler(aDelegate); NSUtils.Assert(handler != null, "Delegate not found!"); handler.priority = priority; rearrangeHandlers(targetedHandlers); rearrangeHandlers(standardHandlers); }